From b5c71e02a4e94c247bc3efce8b0ceaeb9abdba25 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Wed, 7 Nov 2012 23:51:04 +0000 Subject: [PATCH] When decoding RCC3397 domains we should ensure that we have decoded something before changing the last '.' to ' ' and NULL terminating the string. --- dhcp.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dhcp.c b/dhcp.c index d5e0727b..33417467 100644 --- a/dhcp.c +++ b/dhcp.c @@ -401,10 +401,12 @@ get_option_uint8(uint8_t *i, const struct dhcp_message *dhcp, uint8_t option) ssize_t decode_rfc3397(char *out, ssize_t len, int pl, const uint8_t *p) { + const char *start; const uint8_t *r, *q = p; int count = 0, l, hops; uint8_t ltype; + start = out; while (q - p < pl) { r = NULL; hops = 0; @@ -444,15 +446,19 @@ decode_rfc3397(char *out, ssize_t len, int pl, const uint8_t *p) } } /* change last dot to space */ - if (out) + if (out && out != start) *(out - 1) = ' '; if (r) q = r; } /* change last space to zero terminator */ - if (out) - *(out - 1) = 0; + if (out) { + if (out != start) + *(out - 1) = '\0'; + else if (len > 0) + *out = '\0'; + } return count; } -- 2.47.3