Don't include the trailing NUL in encode/decode size.
authorRoy Marples <roy@marples.name>
Thu, 2 Oct 2014 12:08:20 +0000 (12:08 +0000)
committerRoy Marples <roy@marples.name>
Thu, 2 Oct 2014 12:08:20 +0000 (12:08 +0000)
src/libdhcpcd/dhcpcd.c

index 23c5428733ae1ed2523e18475de65d7c3e116600..dc6dc6c65e0437f66c09c5da5c58a41663ba9ac8 100644 (file)
@@ -312,7 +312,6 @@ dhcpcd_encode_string_escape(char *dst, size_t len, const char *src, size_t slen)
                }
                *dst = '\0';
        }
-       bytes++;
 
        return (ssize_t)bytes;
 }
@@ -331,7 +330,7 @@ dhcpcd_decode_string_escape(char *dst, size_t dlen, const char *src)
                        break;
                if (dst && --dlen == 0) {
                        errno = ENOSPC;
-                       return 0;
+                       return -1;
                }
                switch (c) {
                case '\\':
@@ -375,6 +374,11 @@ dhcpcd_decode_string_escape(char *dst, size_t dlen, const char *src)
                }
                bytes++;
        }
+       if (dst && --dlen == 0) {
+               errno = ENOSPC;
+               return -1;
+       }
+       *dst = '\0';
        return bytes;
 }