]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix some valgrind errors.
authorRoy Marples <roy@marples.name>
Sun, 29 Jun 2008 19:48:25 +0000 (19:48 +0000)
committerRoy Marples <roy@marples.name>
Sun, 29 Jun 2008 19:48:25 +0000 (19:48 +0000)
client.c
dhcp.c

index 59321090a57fa8186972c02b5157e4c56bb50357..b5e684acb568926c26598dadd5dbb101bd242932 100644 (file)
--- a/client.c
+++ b/client.c
@@ -531,7 +531,7 @@ client_setup(struct if_state *state, const struct options *options)
                } else {
                        /* Nope, so mark it as-is */
                        len = strlen(options->clientid) + 1;
-                       iface->clientid = xmalloc(len + 1);
+                       iface->clientid = xmalloc(len + 2);
                        iface->clientid[0] = len;
                        iface->clientid[1] = 0; /* string */
                        memcpy(iface->clientid + 2, options->clientid, len);
@@ -549,9 +549,8 @@ client_setup(struct if_state *state, const struct options *options)
                        logger(LOG_INFO, "DUID = %s",
                               hwaddr_ntoa(duid, len));
 
-                       len += 5;
-                       iface->clientid = xmalloc(len);
-                       iface->clientid[0] = len;
+                       iface->clientid = xmalloc(len + 6);
+                       iface->clientid[0] = len + 5;
                        iface->clientid[1] = 255; /* RFC 4361 */
 
                        /* IAID is 4 bytes, so if the iface name is 4 bytes
@@ -570,10 +569,10 @@ client_setup(struct if_state *state, const struct options *options)
 #endif
                if (len == 0) {
                        len = iface->hwlen + 1;
-                       iface->clientid = xmalloc(len);
+                       iface->clientid = xmalloc(len + 1);
                        iface->clientid[0] = len;
                        iface->clientid[1] = iface->family;
-                       memcpy(iface->clientid + 1, iface->hwaddr, iface->hwlen);
+                       memcpy(iface->clientid + 2, iface->hwaddr, iface->hwlen);
                }
        }
 
diff --git a/dhcp.c b/dhcp.c
index e2e3a8f094f95ba5c3e4661faa1d7b6f769f66ee..96f847d658d8033eaf1acb60de0ddc6c85ac8cef 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -775,7 +775,7 @@ make_message(struct dhcp_message **message,
                p += 2;
        }
 
-       if (iface->clientid[0]) {
+       if (iface->clientid) {
                *p++ = DHCP_CLIENTID;
                memcpy(p, iface->clientid, iface->clientid[0] + 1);
                p += iface->clientid[0] + 1;