From ce7beebd593f970d40ca45e201a1f0d0a1e2a41a Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Wed, 26 Jan 2000 22:48:53 +0000 Subject: Discard packets which don't begin with ZVERSIONHDR ("ZEPH") in case we get non-Zephyr packets from somewhere. We've seen it happen on Linux with getting rx packets. --- lib/Zinternal.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'lib/Zinternal.c') diff --git a/lib/Zinternal.c b/lib/Zinternal.c index 99b7de2..9fb9a3f 100644 --- a/lib/Zinternal.c +++ b/lib/Zinternal.c @@ -42,6 +42,7 @@ int __locate_next; ZSubscription_t *__subscriptions_list; int __subscriptions_num; int __subscriptions_next; +int Z_discarded_packets = 0; #ifdef HAVE_KRB4 C_Block __Zephyr_session; @@ -222,10 +223,9 @@ Code_t Z_ReadWait() ZNotice_t notice; ZPacket_t packet; struct sockaddr_in olddest, from; - int from_len, packet_len, part, partof; + int from_len, packet_len, zvlen, part, partof; char *slash; Code_t retval; - register int i; fd_set fds; struct timeval tv; @@ -253,15 +253,12 @@ Code_t Z_ReadWait() if (!packet_len) return (ZERR_EOF); - /* XXX Check for null data (debugging) */ - for (i = packet_len - 1; i >= 0; i--) - if (packet[i]) - goto not_all_null; -#ifdef Z_DEBUG - Z_debug ("got null packet from %s", inet_ntoa (from.sin_addr)); -#endif - return ZERR_NONE; - not_all_null: + /* Ignore obviously non-Zephyr packets. */ + zvlen = sizeof(ZVERSIONHDR) - 1; + if (packet_len < zvlen || memcmp(packet, ZVERSIONHDR, zvlen) != 0) { + Z_discarded_packets++; + return (ZERR_NONE); + } /* Parse the notice */ if ((retval = ZParseNotice(packet, packet_len, ¬ice)) != ZERR_NONE) -- cgit v1.2.3