]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
The args sent from control socket do not include a program in argv[0]
authorRoy Marples <roy@marples.name>
Mon, 15 Sep 2014 22:35:00 +0000 (22:35 +0000)
committerRoy Marples <roy@marples.name>
Mon, 15 Sep 2014 22:35:00 +0000 (22:35 +0000)
so we need to adjustem them to pretend that they do.
Tests show that getopt(3) doesn't look at argv[0] so it's safe(ish).

dhcpcd.c

index 250b9e53395ec53bf208396b256cf607db7ee73d..5c2fe2fac7e49d0424fbaf20a33b0eff82e0c3f2 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -1159,6 +1159,10 @@ dhcpcd_handleargs(struct dhcpcd_ctx *ctx, struct fd_list *fd,
        free(tmp);
 
        optind = 0;
+       /* Pretend argv[0] is a program - tests show that getopt(3)
+        * still works even if the pointer is out of bounds */
+       argc++;
+       argv--;
        while ((opt = getopt_long(argc, argv, IF_OPTS, cf_options, &oi)) != -1)
        {
                switch (opt) {