Browse Source

start-stop-daemon: fix "both -x and -a" case: -a does override argv[0]

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko 5 years ago
parent
commit
77524a311a
2 changed files with 12 additions and 2 deletions
  1. 5 2
      debianutils/start_stop_daemon.c
  2. 7 0
      testsuite/start-stop-daemon.tests

+ 5 - 2
debianutils/start_stop_daemon.c

@@ -555,7 +555,10 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
 		}
 	}
 #endif
-//bb_error_msg("HERE %d '%s'%s'", __LINE__, argv[0], argv[1]);
-	execvp(argv[0], argv);
+	/* Try:
+	 * strace -oLOG start-stop-daemon -S -x /bin/usleep -a qwerty 500000
+	 * should exec "/bin/usleep", but argv[0] should be "qwerty":
+	 */
+	execvp(execname, argv);
 	bb_perror_msg_and_die("can't execute '%s'", startas);
 }

+ 7 - 0
testsuite/start-stop-daemon.tests

@@ -21,4 +21,11 @@ testing "start-stop-daemon without -x and -a" \
 	"1\n" \
 	"" ""
 
+# Unfortunately, this does not actually check argv[0] correctness,
+# but at least it checks that pathname to exec() is correct
+testing "start-stop-daemon with both -x and -a" \
+	'start-stop-daemon -S -x /bin/false -a qwerty false 2>&1; echo $?' \
+	"1\n" \
+	"" ""
+
 exit $FAILCOUNT