]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix a few memory leaks, DHCPv6 prefix definition and the -V option.
authorRoy Marples <roy@marples.name>
Tue, 3 Dec 2013 23:10:21 +0000 (23:10 +0000)
committerRoy Marples <roy@marples.name>
Tue, 3 Dec 2013 23:10:21 +0000 (23:10 +0000)
dhcp6.c
dhcpcd-definitions.conf
dhcpcd.c
if-options.c

diff --git a/dhcp6.c b/dhcp6.c
index 061d3d8223110f010d6c6d44a500e8baf98a3453..09a0ed69292f9ee77f26d7f744bfcd1d8bd8e884 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -134,11 +134,11 @@ dhcp6_cleanup(void)
 void
 dhcp6_printoptions(void)
 {
+       size_t i;
        const struct dhcp_opt *opt;
 
-       for (opt = dhcp6_opts; opt->option; opt++)
-               if (opt->v.var)
-                       printf("%05d %s\n", opt->option, opt->v.var);
+       for (i = 0, opt = dhcp6_opts; i < dhcp6_opts_len; i++, opt++)
+               printf("%05d %s\n", opt->option, opt->v.var);
 }
 
 static int
@@ -417,7 +417,7 @@ dhcp6_makemessage(struct interface *ifp)
        len = 0;
        si = NULL;
        if (state->state != DH6S_RELEASE) {
-               for (opt = dhcp6_opts; opt->option; opt++) {
+               for (l = 0, opt = dhcp6_opts; l < dhcp6_opts_len ; l++, opt++) {
                        if (!(opt->type & NOREQ) &&
                            (opt->type & REQUEST ||
                            has_option_mask(ifo->requestmask6, opt->option)))
@@ -662,7 +662,10 @@ dhcp6_makemessage(struct interface *ifp)
                        o->code = htons(D6_OPTION_ORO);
                        o->len = 0;
                        u16 = (uint16_t *)(void *)D6_OPTION_DATA(o);
-                       for (opt = dhcp6_opts; opt->option; opt++) {
+                       for (l = 0, opt = dhcp6_opts;
+                           l < dhcp6_opts_len;
+                           l++, opt++)
+                       {
                                if (!(opt->type & NOREQ) &&
                                    (opt->type & REQUEST ||
                                    has_option_mask(ifo->requestmask6,
@@ -1974,6 +1977,7 @@ static void
 dhcp6_handledata(__unused void *arg)
 {
        ssize_t len;
+       size_t i;
        struct cmsghdr *cm;
        struct in6_pktinfo pkt;
        struct interface *ifp;
@@ -2075,7 +2079,7 @@ dhcp6_handledata(__unused void *arg)
        }
 
        ifo = ifp->options;
-       for (opt = dhcp6_opts; opt->option; opt++) {
+       for (i = 0, opt = dhcp6_opts; i < dhcp6_opts_len; i++, opt++) {
                if (has_option_mask(ifo->requiremask6, opt->option) &&
                    dhcp6_getmoption(opt->option, r, len) == NULL)
                {
index 96984493c727ed5b9461631153a00b081a1d626b..9df5890318a88c0c1f11d6a8162b3b344e8b72d5 100644 (file)
@@ -192,7 +192,7 @@ embed               uint32                  t1
 embed          uint32                  t2
 encap 26       option
 
-define 26      index embed             prefix
+define6 26     index embed             prefix
 embed          uint32                  pltime
 embed          uint32                  vltime
 embed          ip6address              prefix
index 5288ed7c047a820780b177403528891e0161049a..193c9a1add76f23e5d0f682f2f78450436ed7097 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -1155,21 +1155,8 @@ main(int argc, char **argv)
                        i = 2;
                        break;
                case 'V':
-                       printf("Interface options:\n");
-                       if_printoptions();
-#ifdef INET
-                       if (family == 0 || family == AF_INET) {
-                               printf("\nDHCPv4 options:\n");
-                               dhcp_printoptions();
-                       }
-#endif
-#ifdef INET6
-                       if (family == 0 || family == AF_INET6) {
-                               printf("\nDHCPv6 options:\n");
-                               dhcp6_printoptions();
-                       }
-#endif
-                       exit(EXIT_SUCCESS);
+                       i = 3;
+                       break;
                case '?':
                        usage();
                        exit(EXIT_FAILURE);
@@ -1185,6 +1172,26 @@ main(int argc, char **argv)
                        usage();
                exit(EXIT_FAILURE);
        }
+       if (i == 3) {
+               printf("Interface options:\n");
+               if_printoptions();
+#ifdef INET
+               if (family == 0 || family == AF_INET) {
+                       printf("\nDHCPv4 options:\n");
+                       dhcp_printoptions();
+               }
+#endif
+#ifdef INET6
+               if (family == 0 || family == AF_INET6) {
+                       printf("\nDHCPv6 options:\n");
+                       dhcp6_printoptions();
+               }
+#endif
+#ifdef DEBUG_MEMORY
+               cleanup();
+#endif
+               exit(EXIT_SUCCESS);
+       }
        options = if_options->options;
        if (i != 0) {
                if (i == 1)
index c84ef3376a752e03ffcd9733c53af754f7d04fb4..e0839048536eb76e11280122d094a785fbadf003 100644 (file)
@@ -557,7 +557,8 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
        case 'n': /* FALLTHROUGH */
        case 'x': /* FALLTHROUGH */
        case 'T': /* FALLTHROUGH */
-       case 'U': /* We need to handle non interface options */
+       case 'U': /* FALLTHROUGH */
+       case 'V': /* We need to handle non interface options */
                break;
        case 'b':
                ifo->options |= DHCPCD_BACKGROUND;