Fix a potential NULL dereference.
authorRoy Marples <roy@marples.name>
Wed, 12 Nov 2014 07:13:19 +0000 (07:13 +0000)
committerRoy Marples <roy@marples.name>
Wed, 12 Nov 2014 07:13:19 +0000 (07:13 +0000)
src/libdhcpcd/dhcpcd.c

index 9e8c7d9ac82db83eb1de365cac3d623aed665a00..4b9b61e02b7f13c9936f8095d27838deb1e58879 100644 (file)
@@ -374,11 +374,14 @@ dhcpcd_decode_string_escape(char *dst, size_t dlen, const char *src)
                }
                bytes++;
        }
                }
                bytes++;
        }
-       if (dst && --dlen == 0) {
-               errno = ENOSPC;
-               return -1;
+
+       if (dst) {
+               if (--dlen == 0) {
+                       errno = ENOSPC;
+                       return -1;
+               }
+               *dst = '\0';
        }
        }
-       *dst = '\0';
        return bytes;
 }
 
        return bytes;
 }