From: Roy Marples Date: Mon, 15 Sep 2014 22:35:00 +0000 (+0000) Subject: The args sent from control socket do not include a program in argv[0] X-Git-Tag: v6.4.4~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f49ebfb64084ab718c9b38dbea88d0b9b2da7363;p=thirdparty%2Fdhcpcd.git The args sent from control socket do not include a program in argv[0] 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). --- diff --git a/dhcpcd.c b/dhcpcd.c index 250b9e53..5c2fe2fa 100644 --- 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) {