]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
The decode and print functions should not including the trailing NUL
authorRoy Marples <roy@marples.name>
Thu, 2 Oct 2014 13:21:29 +0000 (13:21 +0000)
committerRoy Marples <roy@marples.name>
Thu, 2 Oct 2014 13:21:29 +0000 (13:21 +0000)
in their return values to match other functions.

dhcp-common.c
ipv6nd.c
script.c

index 72fdceaa59c134a23de618a978a891a9dc35e454..90548f8caa992d0a2d0aad1c2481992e25679fce 100644 (file)
@@ -347,6 +347,9 @@ decode_rfc3397(char *out, size_t len, const uint8_t *p, size_t pl)
                        *out = '\0';
        }
 
+       if (count)
+               /* Don't count the trailing NUL */
+               count--;
        return (ssize_t)count;
 }
 
@@ -398,7 +401,7 @@ valid_domainname(char *lbl, int type)
                {
                        if (++len > 63) {
                                errno = ERANGE;
-                               errset = 1;
+                               errset = 1;
                                break;
                        }
                } else
@@ -434,7 +437,7 @@ print_string(char *dst, size_t len, int type, const uint8_t *data, size_t dl)
        odst = dst;
        bytes = 0;
        e = data + dl;
-       
+
        while (data < e) {
                c = *data++;
                if (type & BINHEX) {
@@ -516,7 +519,6 @@ print_string(char *dst, size_t len, int type, const uint8_t *data, size_t dl)
                }
 
        }
-       bytes++;
 
        return (ssize_t)bytes;
 }
@@ -592,7 +594,7 @@ print_option(char *s, size_t len, int type, const uint8_t *data, size_t dl,
                sl = decode_rfc3397(NULL, 0, data, dl);
                if (sl == 0 || sl == -1)
                        return sl;
-               l = (size_t)sl;
+               l = (size_t)sl + 1;
                tmp = malloc(l);
                if (tmp == NULL)
                        return -1;
@@ -627,7 +629,7 @@ print_option(char *s, size_t len, int type, const uint8_t *data, size_t dl,
                        *s++ = '1';
                        *s = '\0';
                }
-               return 2;
+               return 1;
        }
 
        if (!s) {
@@ -661,14 +663,14 @@ print_option(char *s, size_t len, int type, const uint8_t *data, size_t dl,
                                        l += (size_t)sl;
                                data += 16;
                        }
-                       return (ssize_t)(l + 1);
+                       return (ssize_t)l;
                }
 #endif
                else {
                        errno = EINVAL;
                        return -1;
                }
-               return (ssize_t)((l + 1) * dl);
+               return (ssize_t)(l * dl);
        }
 
        t = data;
@@ -749,7 +751,7 @@ dhcp_envoption1(char **env, const char *prefix,
                e = 0;
        if (prefix)
                e += strlen(prefix);
-       e += (size_t)len + 4;
+       e += (size_t)len + 2;
        if (env == NULL)
                return e;
        v = val = *env = malloc(e);
@@ -762,7 +764,7 @@ dhcp_envoption1(char **env, const char *prefix,
        else
                v += snprintf(val, e, "%s=", prefix);
        if (len != 0)
-               print_option(v, (size_t)len, opt->type, od, ol, ifname);
+               print_option(v, (size_t)len + 1, opt->type, od, ol, ifname);
        return e;
 }
 
index 640df971feb3fdd026c557d664759895c137f5db..0cf15780ab5413d532641f16f086c5d0d77478f4 100644 (file)
--- a/ipv6nd.c
+++ b/ipv6nd.c
@@ -1005,7 +1005,7 @@ ipv6nd_handlera(struct ipv6_ctx *ctx, struct interface *ifp,
                                    ifp->name);
                                continue;
                        } else {
-                               l = (size_t)r;
+                               l = (size_t)r + 1;
                                tmp = malloc(l);
                                if (tmp) {
                                        decode_rfc3397(tmp, l, op, n);
@@ -1013,6 +1013,7 @@ ipv6nd_handlera(struct ipv6_ctx *ctx, struct interface *ifp,
                                        n = (size_t)print_string(NULL, 0,
                                            STRING | ARRAY | DOMAIN,
                                            (const uint8_t *)tmp, l);
+                                       n++;
                                        opt = malloc(n);
                                        if (opt) {
                                                print_string(opt, n,
index 80f892c3eb64116ac54ccc6191cfe6fd0438a231..2419037d243a32408d0269e86e7a63570f9123a0 100644 (file)
--- a/script.c
+++ b/script.c
@@ -384,7 +384,7 @@ make_env(const struct interface *ifp, const char *reason, char ***argv)
                if (psl != -1) {
                        EMALLOC(elen, pfx_len + (size_t)psl + 1);
                        memcpy(env[elen], pfx, pfx_len);
-                       print_string(env[elen] + pfx_len, (size_t)psl,
+                       print_string(env[elen] + pfx_len, (size_t)psl + 1,
                            ESCSTRING,
                            (const uint8_t *)ifp->ssid, ifp->ssid_len);
                        elen++;