From 573be0bc6dddf207057759f61eab7220276b783c Mon Sep 17 00:00:00 2001 From: Michael Graff Date: Fri, 28 Jan 2000 00:33:14 +0000 Subject: [PATCH] misc parsing and rendering nits --- lib/lwres/include/lwres/result.h | 1 + lib/lwres/lwres_gabn.c | 20 ++++++++++---------- lib/lwres/lwresutil.c | 21 +++++++++++++++++---- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lib/lwres/include/lwres/result.h b/lib/lwres/include/lwres/result.h index e65d5b3366..e59595df11 100644 --- a/lib/lwres/include/lwres/result.h +++ b/lib/lwres/include/lwres/result.h @@ -27,5 +27,6 @@ #define LWRES_R_IOERROR -6 #define LWRES_R_NOTIMPLEMENTED -7 #define LWRES_R_UNEXPECTED -8 +#define LWRES_R_TRAILINGDATA -9 #endif /* LWRES_RESULT_H */ diff --git a/lib/lwres/lwres_gabn.c b/lib/lwres/lwres_gabn.c index 192e6c464a..69cd1f7d77 100644 --- a/lib/lwres/lwres_gabn.c +++ b/lib/lwres/lwres_gabn.c @@ -288,15 +288,6 @@ lwres_gabnresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b, if (ret != LWRES_R_SUCCESS) goto out; - /* - * Pull off the addresses. - */ - for (x = 0 ; x < gabn->naddrs ; x++) { - ret = lwres_addr_parse(b, &gabn->addrs[x]); - if (ret != LWRES_R_SUCCESS) - goto out; - } - /* * Parse off the aliases. */ @@ -307,8 +298,17 @@ lwres_gabnresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b, goto out; } + /* + * Pull off the addresses. + */ + for (x = 0 ; x < gabn->naddrs ; x++) { + ret = lwres_addr_parse(b, &gabn->addrs[x]); + if (ret != LWRES_R_SUCCESS) + goto out; + } + if (LWRES_BUFFER_REMAINING(b) != 0) { - ret = LWRES_R_UNEXPECTEDEND; + ret = LWRES_R_TRAILINGDATA; goto out; } diff --git a/lib/lwres/lwresutil.c b/lib/lwres/lwresutil.c index ac790849db..57fe69f132 100644 --- a/lib/lwres/lwresutil.c +++ b/lib/lwres/lwresutil.c @@ -57,19 +57,32 @@ lwres_string_parse(lwres_buffer_t *b, char **c, isc_uint16_t *len) REQUIRE(b != NULL); + /* + * Pull off the length (2 bytes) + */ if (!SPACE_REMAINING(b, sizeof(isc_uint16_t))) return (LWRES_R_UNEXPECTEDEND); datalen = lwres_buffer_getuint16(b); - datalen++; + + /* + * Set the pointer to this string to the right place, then + * advance the buffer pointer. + */ if (!SPACE_REMAINING(b, datalen)) return (LWRES_R_UNEXPECTEDEND); - string = b->base + b->current; - lwres_buffer_forward(b, datalen); + /* + * Skip the "must be zero" byte. + */ + if (!SPACE_REMAINING(b, 1)) + return (LWRES_R_UNEXPECTEDEND); + if (0 != lwres_buffer_getuint8(b)) + return (LWRES_R_FAILURE); + if (len != NULL) - *len = datalen - 1; + *len = datalen; if (c != NULL) *c = string;