]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
When decoding RCC3397 domains we should ensure that we have
authorRoy Marples <roy@marples.name>
Wed, 7 Nov 2012 23:51:04 +0000 (23:51 +0000)
committerRoy Marples <roy@marples.name>
Wed, 7 Nov 2012 23:51:04 +0000 (23:51 +0000)
decoded something before changing the last '.' to ' ' and
NULL terminating the string.

dhcp.c

diff --git a/dhcp.c b/dhcp.c
index d5e0727b5b147fa0e3483e8eadcd5668ebef4a66..33417467367fab46582595aef4d9a323e7a95da3 100644 (file)
--- 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;  
 }