]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Trim trailing NULLs from string options, #120.
authorRoy Marples <roy@marples.name>
Tue, 4 Nov 2008 10:04:40 +0000 (10:04 +0000)
committerRoy Marples <roy@marples.name>
Tue, 4 Nov 2008 10:04:40 +0000 (10:04 +0000)
dhcp.c

diff --git a/dhcp.c b/dhcp.c
index 0f61e1876abbee73bb01839bc07f9266cb09c871..e537168465ca88ddd7bb68d93c3bfc07b1b8e930 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -1009,13 +1009,21 @@ static ssize_t
 print_string(char *s, ssize_t len, int dl, const uint8_t *data)
 {
        uint8_t c;
-       const uint8_t *e;
+       const uint8_t *e, *p;
        ssize_t bytes = 0;
        ssize_t r;
 
        e = data + dl;
        while (data < e) {
                c = *data++;
+               if (c == '\0') {
+                       /* If rest is all NULL, skip it. */
+                       for (p = data; p < e; p++)
+                               if (*p != '\0')
+                                       break;
+                       if (p == e)
+                               break;
+               }
                if (!isascii(c) || !isprint(c)) {
                        if (s) {
                                if (len < 5) {