From 8e0db6ca540f858a8fa2d832ca37459e1198b4d1 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Thu, 24 Aug 2006 22:56:19 +0000 Subject: [PATCH] Added one test, fixed problems --- read.c | 13 ++++++++----- test.c | 10 +++++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/read.c b/read.c index 1c14722..07e3643 100644 --- a/read.c +++ b/read.c @@ -38,7 +38,7 @@ readname_loop(char *packet, char **src, char *dst, size_t length, size_t loop) if((c & 0xc0) == 0xc0) { dummy = packet + (((s[-1] & 0x3f) << 8) | s[0]); len += readname_loop(packet, &dummy, d, length - len, loop - 1); - break; + goto end; } while(c && len < length - 1) { @@ -48,16 +48,19 @@ readname_loop(char *packet, char **src, char *dst, size_t length, size_t loop) c--; } - if (len < length - 1) { + if (len >= length - 1) { break; /* We used up all space */ } - if (*s != 0) + if (*s != 0) { *d++ = '.'; + len++; + } } - (*src) = s+1; - dst[len++] = '\0'; + +end: + (*src) = s+1; return len; } diff --git a/test.c b/test.c index f882f2f..6d534a4 100644 --- a/test.c +++ b/test.c @@ -122,7 +122,10 @@ test_readname() "\x3FzBCDEFGHIJKLMNOPQURSTUVXYZ0123456789abcdefghijklmnopqrstuvxyzAA" "\x3FzBCDEFGHIJKLMNOPQURSTUVXYZ0123456789abcdefghijklmnopqrstuvxyzAA" "\x3FzBCDEFGHIJKLMNOPQURSTUVXYZ0123456789abcdefghijklmnopqrstuvxyzAA" - "\x00\x01\x00\x01"; + "\x00\x00\x01\x00\x01"; + char onejump[] = + "AA\x81\x80\x00\x01\x00\x00\x00\x00\x00\x00" + "\x02hh\xc0\x15\x00\x01\x00\x01\x05zBCDE\x00"; char buf[1024]; char *data; int rv; @@ -148,6 +151,11 @@ test_readname() rv = readname(longname, &data, buf, 256); assert(buf[256] == '\a'); + bzero(buf, sizeof(buf)); + data = onejump + sizeof(HEADER); + rv = readname(onejump, &data, buf, 256); + assert(rv == 9); + printf("OK\n"); }