Skip to contentSkip to conversation

execl(), execlp() and execle() require proper termination of argument list

PATCH In review David Hildenbrand 4 participants 7 messages Nov 25, 2022 – Dec 5, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 execl(), execlp() and execle() require proper termination of argument list

The manpage of exec() says:
"The list of arguments must be terminated by a null pointer, and, since
these are variadic functions, this pointer must be cast (char *) NULL."

So let's fix all instances that either call these functions directly or through the SAFE_EXEC* helpers.

Note that we don't have to worry about cases such as in prctl06.c, whereby NULL is stored into a char * array first.

---
 pan/ltp-pan.c                                            | 2 +-
 testcases/kernel/connectors/pec/event_generator.c        | 3 ++-
 testcases/kernel/controllers/freezer/fork_exec_loop.c    | 2 +-
 testcases/kernel/fs/fs_perms/fs_perms.c                  | 4 ++--
 testcases/kernel/fs/ftest/ftest01.c                      | 2 +-
 testcases/kernel/fs/ftest/ftest02.c                      | 4 ++--
 testcases/kernel/fs/ftest/ftest03.c                      | 2 +-
 testcases/kernel/fs/ftest/ftest05.c                      | 2 +-
 testcases/kernel/fs/ftest/ftest06.c                      | 4 ++--
 testcases/kernel/fs/ftest/ftest07.c                      | 2 +-
 testcases/kernel/sched/sched_stress/sched_driver.c       | 3 ++-
 testcases/kernel/sched/sched_stress/sched_tc6.c          | 2 +-
 testcases/kernel/security/cap_bound/exec_with_inh.c      | 2 +-
 testcases/kernel/security/cap_bound/exec_without_inh.c   | 2 +-
 testcases/kernel/security/dirtyc0w/dirtyc0w.c            | 2 +-
 .../kernel/security/dirtyc0w_shmem/dirtyc0w_shmem.c      | 3 ++-
 testcases/kernel/security/filecaps/verify_caps_exec.c    | 2 +-
 testcases/kernel/security/tomoyo/tomoyo_file_test.c      | 2 +-
 testcases/kernel/security/tomoyo/tomoyo_new_file_test.c  | 4 ++--
 testcases/kernel/syscalls/creat/creat07.c                | 2 +-
 testcases/kernel/syscalls/execl/execl01.c                | 2 +-
 testcases/kernel/syscalls/execle/execle01.c              | 3 ++-
 testcases/kernel/syscalls/execlp/execlp01.c              | 3 ++-
 testcases/kernel/syscalls/fanotify/fanotify10.c          | 2 +-
 testcases/kernel/syscalls/fanotify/fanotify12.c          | 2 +-
 testcases/kernel/syscalls/fcntl/fcntl07.c                | 2 +-
 testcases/kernel/syscalls/getrusage/getrusage03.c        | 9 +++++----
 testcases/kernel/syscalls/mount/mount03.c                | 4 ++--
 testcases/kernel/syscalls/open/open12.c                  | 2 +-
 testcases/kernel/syscalls/openat/openat02.c              | 2 +-
 testcases/kernel/syscalls/pipe2/pipe2_02.c               | 2 +-
 testcases/kernel/syscalls/ptrace/spawn_ptrace_child.h    | 2 +-
 testcases/kernel/syscalls/setpgid/setpgid03.c            | 2 +-
 testcases/kernel/syscalls/setrlimit/setrlimit04.c        | 2 +-
 testcases/network/nfsv4/acl/acl1.c                       | 2 +-
 .../conformance/interfaces/sem_unlink/2-2.c              | 2 +-
 .../conformance/interfaces/sigaltstack/9-1.c             | 2 +-
 .../conformance/interfaces/timer_create/9-1.c            | 2 +-
 38 files changed, 52 insertions(+), 46 deletions(-)
pan/ltp-pan.c +1 -1
index 0bdb51477..9f83033ed 100644
@@ -1034,7 +1034,7 @@ run_child(struct coll_entry *colle, struct tag_pgrp *active, int quiet_mode,
 		 * cmd directly.
 		 */
 		if (strpbrk(c_cmdline, "\"';|<>$\\")) {
-			execlp("sh", "sh", "-c", c_cmdline, NULL);
+			execlp("sh", "sh", "-c", c_cmdline, (char *)NULL);
 			errlen = sprintf(errbuf,
 					 "pan(%s): execlp of '%s' (tag %s) failed.  errno:%d %s",
 					 panname, c_cmdline, colle->name, errno,
testcases/kernel/connectors/pec/event_generator.c +2 -1
index 4945058ff..78bfd9e89 100644
@@ -68,7 +68,8 @@ static void gen_exec(void)
 	 * the shell script, before the first exec.
 	 */
 	sprintf(buf, "%u", nr_event - 1);
-	SAFE_EXECLP(prog_name, prog_name, "-e", "exec", "-n", buf, NULL);
+	SAFE_EXECLP(prog_name, prog_name, "-e", "exec", "-n", buf,
+		    (char *)NULL);
 }
 
 /*
testcases/kernel/controllers/freezer/fork_exec_loop.c +1 -1
index 6b6218501..8ef8504e0 100644
@@ -31,7 +31,7 @@ int main(int argc, char **argv)
 
 		for (i = 0; i < count; i++)
 			if (fork() == 0)
-				execlp("/bin/true", "true", NULL);
+				execlp("/bin/true", "true", (char *)NULL);
 
 		for (i = 0; i < count; i++)
 			wait(&s);
testcases/kernel/fs/fs_perms/fs_perms.c +2 -2
index e8c5f536f..3bd44a900 100644
@@ -127,9 +127,9 @@ static int testfperm(const char *file_name, int flag, int user_id,
 			 * no binmft handler for it, execl does not.
 			 */
 			if (flag)
-				execl(file_name, file_name, NULL);
+				execl(file_name, file_name, (char *)NULL);
 			else
-				execlp(file_name, "test", NULL);
+				execlp(file_name, "test", (char *)NULL);
 
 			exit(1);
 			break;
testcases/kernel/fs/ftest/ftest01.c +1 -1
index 31203d689..fa8fef638 100644
@@ -218,7 +218,7 @@ static void runtest(void)
 	}
 
 	if (pid == 0) {
-		execl("/bin/rm", "rm", "-rf", fuss, NULL);
+		execl("/bin/rm", "rm", "-rf", fuss, (char *)NULL);
 		exit(1);
 	}
 
testcases/kernel/fs/ftest/ftest02.c +2 -2
index a416a9884..80d8c6060 100644
@@ -203,7 +203,7 @@ int main(void)
 	}
 
 	if (pid == 0) {
-		execl("/bin/rm", "rm", "-rf", homedir, NULL);
+		execl("/bin/rm", "rm", "-rf", homedir, (char *)NULL);
 		exit(1);
 	} else
 		wait(&status);
@@ -220,7 +220,7 @@ int main(void)
 	}
 
 	if (pid == 0) {
-		execl("/bin/rm", "rm", "-rf", dirname, NULL);
+		execl("/bin/rm", "rm", "-rf", dirname, (char *)NULL);
 		exit(1);
 	} else
 		wait(&status);
testcases/kernel/fs/ftest/ftest03.c +1 -1
index ed69e5736..a9573af78 100644
@@ -237,7 +237,7 @@ static void runtest(void)
 	}
 
 	if (pid == 0) {
-		execl("/bin/rm", "rm", "-rf", fuss, NULL);
+		execl("/bin/rm", "rm", "-rf", fuss, (char *)NULL);
 		exit(1);
 	} else
 		wait(&status);
testcases/kernel/fs/ftest/ftest05.c +1 -1
index 8d8e6d497..039f9efbb 100644
@@ -218,7 +218,7 @@ static void runtest(void)
 	}
 
 	if (pid == 0) {
-		execl("/bin/rm", "rm", "-rf", fuss, NULL);
+		execl("/bin/rm", "rm", "-rf", fuss, (char *)NULL);
 		exit(1);
 	}
 
testcases/kernel/fs/ftest/ftest06.c +2 -2
index c3aebe5bb..ac7c91bb4 100644
@@ -219,7 +219,7 @@ int main(int ac, char *av[])
 		}
 
 		if (pid == 0) {
-			execl("/bin/rm", "rm", "-rf", homedir, NULL);
+			execl("/bin/rm", "rm", "-rf", homedir, (char *)NULL);
 
 		} else
 			wait(&status);
@@ -234,7 +234,7 @@ int main(int ac, char *av[])
 			tst_brkm(TBROK | TERRNO, NULL, "fork failed");
 		}
 		if (pid == 0) {
-			execl("/bin/rm", "rm", "-rf", dirname, NULL);
+			execl("/bin/rm", "rm", "-rf", dirname, (char *)NULL);
 			exit(1);
 		} else
 			wait(&status);
testcases/kernel/fs/ftest/ftest07.c +1 -1
index 3b5b2a419..a865161cf 100644
@@ -237,7 +237,7 @@ static void runtest(void)
 	}
 
 	if (pid == 0) {
-		execl("/bin/rm", "rm", "-rf", fuss, NULL);
+		execl("/bin/rm", "rm", "-rf", fuss, (char *)NULL);
 		exit(1);
 	} else
 		wait(&status);
testcases/kernel/sched/sched_stress/sched_driver.c +2 -1
index 61573d788..cc5ccff3f 100644
@@ -323,7 +323,8 @@ int start_testcase(char *name1, char *name2, char *param1, char *param2,
 	case -1:
 		exit(-1);
 	case 0:
-		execl(name1, name2, param1, param2, param3, param4, NULL);
+		execl(name1, name2, param1, param2, param3, param4,
+		      (char *)NULL);
 		printf("ERROR: start_testcase():  execl failed.\n");
 		exit(-1);
 	default:
testcases/kernel/sched/sched_stress/sched_tc6.c +1 -1
index e70e8f250..3128554e3 100644
@@ -289,7 +289,7 @@ int fork_realtime(char **args)
 		/* child process */
 	case 0:
 		if (execl(*args, *args, REAL_TIME, results_file, priority,
-			  NO_FORK, NULL) < 0)
+			  NO_FORK, (char *)NULL) < 0)
 			sys_error("execl failed", __FILE__, __LINE__);
 
 		/* parent process */
testcases/kernel/security/cap_bound/exec_with_inh.c +1 -1
index 01b755808..966165898 100644
@@ -80,7 +80,7 @@ int main(int argc, char *argv[])
 	}
 
 	/* execute "check_pe 1" */
-	execl("check_pe", "check_pe", "1", NULL);
+	execl("check_pe", "check_pe", "1", (char *)NULL);
 	tst_resm(TBROK, "Failed to execute check_pe (errno %d)", errno);
 #else /* HAVE_LIBCAP */
 	tst_resm(TCONF, "System doesn't have POSIX capabilities.");
testcases/kernel/security/cap_bound/exec_without_inh.c +1 -1
index 10220e10e..f31fce05b 100644
@@ -77,7 +77,7 @@ int main(void)
 	}
 
 	/* execute "check_pe 0" */
-	execl("check_pe", "check_pe", "0", NULL);
+	execl("check_pe", "check_pe", "0", (char *)NULL);
 	tst_resm(TBROK, "Failed to execute check_pe (errno %d)", errno);
 #else /* libcap */
 	tst_resm(TCONF, "System doesn't have POSIX capabilities.");
testcases/kernel/security/dirtyc0w/dirtyc0w.c +1 -1
index 487a52601..6d2fa7d6a 100644
@@ -70,7 +70,7 @@ void dirtyc0w_test(void)
 	if (!pid) {
 		SAFE_SETGID(nobody_gid);
 		SAFE_SETUID(nobody_uid);
-		SAFE_EXECLP("dirtyc0w_child", "dirtyc0w_child", NULL);
+		SAFE_EXECLP("dirtyc0w_child", "dirtyc0w_child", (char *)NULL);
 	}
 
 	TST_CHECKPOINT_WAIT(0);
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem.c +2 -1
index f885a9283..1e3b194e7 100644
@@ -69,7 +69,8 @@ static void dirtyc0w_shmem_test(void)
 	if (!pid) {
 		SAFE_SETGID(nobody_gid);
 		SAFE_SETUID(nobody_uid);
-		SAFE_EXECLP("dirtyc0w_shmem_child", "dirtyc0w_shmem_child", NULL);
+		SAFE_EXECLP("dirtyc0w_shmem_child", "dirtyc0w_shmem_child",
+			    (char *)NULL);
 	}
 
 	TST_CHECKPOINT_WAIT(0);
testcases/kernel/security/filecaps/verify_caps_exec.c +1 -1
index 4cabcc542..da5378aa4 100644
@@ -168,7 +168,7 @@ static int fork_drop_and_exec(int keepperms, cap_t expected_caps)
 		drop_root(keepperms);
 		print_my_caps();
 		sprintf(buf, "%d", seqno);
-		ret = execlp(TSTPATH, TSTPATH, buf, NULL);
+		ret = execlp(TSTPATH, TSTPATH, buf, (char *)NULL);
 		capstxt = cap_to_text(expected_caps, NULL);
 		snprintf(buf, 200, "failed to run as %s\n", capstxt);
 		cap_free(capstxt);
testcases/kernel/security/tomoyo/tomoyo_file_test.c +1 -1
index 003f47720..091812628 100644
@@ -96,7 +96,7 @@ static void stage_file_test(void)
 		if (pipe(pipe_fd) == -1)
 			err(1, "pipe");
 		if (fork() == 0) {
-			execl("/bin/true", "/bin/true", NULL);
+			execl("/bin/true", "/bin/true", (char *)NULL);
 			if (write(pipe_fd[1], &errno, sizeof(errno)) == -1)
 				err(1, "write");
 			_exit(0);
testcases/kernel/security/tomoyo/tomoyo_new_file_test.c +2 -2
index eb912d726..fc6dc83b7 100644
@@ -156,7 +156,7 @@ static void stage_file_test(void)
 	if (pipe(pipe_fd) == -1)
 		err(1, "pipe");
 	if (fork() == 0) {
-		execl("/bin/true", "/bin/true", NULL);
+		execl("/bin/true", "/bin/true", (char *)NULL);
 		if (write(pipe_fd[1], &errno, sizeof(errno)) == -1)
 			err(1, "write");
 		exit(0);
@@ -173,7 +173,7 @@ static void stage_file_test(void)
 	if (pipe(pipe_fd) == -1)
 		err(1, "pipe");
 	if (fork() == 0) {
-		execl("/bin/true", "/bin/true", NULL);
+		execl("/bin/true", "/bin/true", (char *)NULL);
 		if (write(pipe_fd[1], &errno, sizeof(errno)) == -1)
 			err(1, "write");
 		_exit(0);
testcases/kernel/syscalls/creat/creat07.c +1 -1
index 7bd32ab4d..f55de29af 100644
@@ -25,7 +25,7 @@ static void verify_creat(void)
 
 	pid = SAFE_FORK();
 	if (pid == 0) {
-		SAFE_EXECL(TEST_APP, TEST_APP, NULL);
+		SAFE_EXECL(TEST_APP, TEST_APP, (char *)NULL);
 		exit(1);
 	}
 
testcases/kernel/syscalls/execl/execl01.c +1 -1
index 9268d4976..47cc527b1 100644
@@ -25,7 +25,7 @@ static void verify_execl(void)
 
 	pid = SAFE_FORK();
 	if (pid == 0) {
-		TEST(execl(path, "execl01_child", "canary", NULL));
+		TEST(execl(path, "execl01_child", "canary", (char *)NULL));
 		tst_brk(TFAIL | TTERRNO,
 			"Failed to execute execl01_child");
 	}
testcases/kernel/syscalls/execle/execle01.c +2 -1
index 917dc892f..edad8ac3a 100644
@@ -30,7 +30,8 @@ static void verify_execle(void)
 
 	pid = SAFE_FORK();
 	if (pid == 0) {
-		TEST(execle(path, "execle01_child", "canary", NULL, envp));
+		TEST(execle(path, "execle01_child", "canary", (char *)NULL,
+			    envp));
 		tst_brk(TFAIL | TTERRNO,
 			"Failed to execute execl01_child");
 	}
testcases/kernel/syscalls/execlp/execlp01.c +2 -1
index 99ea59490..37d464a3a 100644
@@ -23,7 +23,8 @@ static void verify_execlp(void)
 
 	pid = SAFE_FORK();
 	if (pid == 0) {
-		TEST(execlp("execlp01_child", "execlp01_child", "canary", NULL));
+		TEST(execlp("execlp01_child", "execlp01_child", "canary",
+		     (char *)NULL));
 		tst_brk(TFAIL | TTERRNO,
 			"Failed to execute execlp01_child");
 	}
testcases/kernel/syscalls/fanotify/fanotify10.c +1 -1
index d0e9194e7..b9af94116 100644
@@ -711,7 +711,7 @@ static int generate_event(struct tcase *tc, unsigned long long expected_mask)
 
 		foreach_path(tc, path, event_path) {
 			if (expected_mask & FAN_OPEN_EXEC) {
-				SAFE_EXECL(path, path, NULL);
+				SAFE_EXECL(path, path, (char *)NULL);
 			} else {
 				fd = SAFE_OPEN(path, O_RDONLY);
 
testcases/kernel/syscalls/fanotify/fanotify12.c +1 -1
index 7f8e97b17..5b15ba8e0 100644
@@ -118,7 +118,7 @@ static int generate_events(void)
 		if (fd > 0)
 			SAFE_CLOSE(fd);
 
-		SAFE_EXECL(TEST_APP, TEST_APP, NULL);
+		SAFE_EXECL(TEST_APP, TEST_APP, (char *)NULL);
 		exit(1);
 	}
 
testcases/kernel/syscalls/fcntl/fcntl07.c +1 -1
index 9108b79c1..16b23be6b 100644
@@ -106,7 +106,7 @@ static void verify_cloexec(struct tcase *tc)
 		tst_resm(TBROK | TERRNO, "fork() failed");
 		return;
 	case 0:
-		execlp(TCID, TCID, "-T", pidname, NULL);
+		execlp(TCID, TCID, "-T", pidname, (char *)NULL);
 
 		/* the ONLY reason to do this is to get the errno printed out */
 		fprintf(stderr, "exec(%s, %s, -T, %s) failed.  Errno %s [%d]\n",
testcases/kernel/syscalls/getrusage/getrusage03.c +5 -4
index 7e7a1f555..8ed0ce094 100644
@@ -76,7 +76,7 @@ static void grandchild_maxrss(void)
 {
 	if (!SAFE_FORK())
 		SAFE_EXECLP("getrusage03_child", "getrusage03_child",
-			    "grand_consume", "300", NULL);
+			    "grand_consume", "300", (char *)NULL);
 	tst_reap_children();
 	SAFE_GETRUSAGE(RUSAGE_CHILDREN, &ru);
 
@@ -96,7 +96,7 @@ static void zombie(void)
 
 	if (!pid)
 		SAFE_EXECLP("getrusage03_child", "getrusage03_child",
-			    "consume", "400", NULL);
+			    "consume", "400", (char *)NULL);
 
 	TST_PROCESS_STATE_WAIT(pid, 'Z', 0);
 	SAFE_GETRUSAGE(RUSAGE_CHILDREN, &ru);
@@ -125,7 +125,7 @@ static void sig_ign(void)
 
 	if (!pid)
 		SAFE_EXECLP("getrusage03_child", "getrusage03_child",
-			    "consume", "500", NULL);
+			    "consume", "500", (char *)NULL);
 
 	TST_PROCESS_EXIT_WAIT(pid, 0);
 	SAFE_GETRUSAGE(RUSAGE_CHILDREN, &ru);
@@ -149,7 +149,8 @@ static void inherit_exec(void)
 		sprintf(str_maxrss_child, "%ld", ru.ru_maxrss);
 
 		SAFE_EXECLP("getrusage03_child", "getrusage03_child",
-			    "compare", str_maxrss_self, str_maxrss_child, NULL);
+			    "compare", str_maxrss_self, str_maxrss_child,
+			    (char *)NULL);
 	}
 	tst_reap_children();
 }
testcases/kernel/syscalls/mount/mount03.c +2 -2
index 397c1bf81..35d13b6c7 100644
@@ -61,7 +61,7 @@ static void test_noexec(void)
 {
 	snprintf(file, PATH_MAX, "%s/noexec", MNTPOINT);
 	otfd = SAFE_OPEN(file, O_CREAT | O_RDWR, 0700);
-	TST_EXP_FAIL(execlp(file, basename(file), NULL), EACCES);
+	TST_EXP_FAIL(execlp(file, basename(file), (char *)NULL), EACCES);
 }
 
 static void test_remount(void)
@@ -88,7 +88,7 @@ static void test_nosuid(void)
 			SAFE_CHMOD(BIN_PATH, SUID_MODE);
 
 		SAFE_SETREUID(nobody_uid, nobody_uid);
-		SAFE_EXECL(BIN_PATH, BIN_PATH, NULL);
+		SAFE_EXECL(BIN_PATH, BIN_PATH, (char *)NULL);
 		tst_brk(TFAIL | TTERRNO, "Failed to execute %s", BIN_PATH);
 	}
 
testcases/kernel/syscalls/open/open12.c +1 -1
index 02ef5b5b0..abb252ada 100644
@@ -205,7 +205,7 @@ static void test_cloexec(void)
 		tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
 
 	if (pid == 0) {
-		if (execlp("open12_child", "open12_child", buf, NULL))
+		if (execlp("open12_child", "open12_child", buf, (char *)NULL))
 			exit(2);
 	}
 
testcases/kernel/syscalls/openat/openat02.c +1 -1
index b0a6ff78f..13c805bfd 100644
@@ -165,7 +165,7 @@ void testfunc_cloexec(void)
 		tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
 
 	if (pid == 0) {
-		if (execlp(TEST_APP, TEST_APP, buf, NULL))
+		if (execlp(TEST_APP, TEST_APP, buf, (char *)NULL))
 			exit(2);
 	}
 
testcases/kernel/syscalls/pipe2/pipe2_02.c +1 -1
index ee317668b..84eb08b36 100644
@@ -34,7 +34,7 @@ static void verify_pipe2(void)
 	sprintf(buf, "%d", fds[1]);
 	pid = SAFE_FORK();
 	if (pid == 0)
-		SAFE_EXECLP(TESTBIN, TESTBIN, buf, NULL);
+		SAFE_EXECLP(TESTBIN, TESTBIN, buf, (char *)NULL);
 
 	SAFE_WAIT(&status);
 	if (WIFEXITED(status)) {
testcases/kernel/syscalls/ptrace/spawn_ptrace_child.h +1 -1
index 83de9b447..dd6b68948 100644
@@ -95,7 +95,7 @@ static void make_a_baby(int argc, char *argv[])
 		tst_exit();
 	}
 
-	execlp(argv[0], argv[0], "child", NULL);
+	execlp(argv[0], argv[0], "child", (char *)NULL);
 	tst_resm(TFAIL, "execlp() failed");
 	tst_exit();
 }
testcases/kernel/syscalls/setpgid/setpgid03.c +1 -1
index 79ca23e08..941a7e5af 100644
@@ -49,7 +49,7 @@ static void run(void)
 	/* child after exec() we are no longer allowed to set pgid */
 	child_pid = SAFE_FORK();
 	if (!child_pid)
-		SAFE_EXECLP(TEST_APP, TEST_APP, NULL);
+		SAFE_EXECLP(TEST_APP, TEST_APP, (char *)NULL);
 
 	TST_CHECKPOINT_WAIT(0);
 
testcases/kernel/syscalls/setrlimit/setrlimit04.c +1 -1
index 5648f5103..c897b643a 100644
@@ -35,7 +35,7 @@ static void test_setrlimit(void)
 
 	child = SAFE_FORK();
 	if (child == 0)
-		SAFE_EXECLP("/bin/true", "/bin/true", NULL);
+		SAFE_EXECLP("/bin/true", "/bin/true", (char *)NULL);
 	SAFE_WAITPID(child, &status, 0);
 
 	if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
testcases/network/nfsv4/acl/acl1.c +1 -1
index ad778cd33..ea71cf977 100644
@@ -52,7 +52,7 @@ int do_file_op(char *filename)
 	uid = geteuid();
 	strcat(str, filename);
 
-	exe = execl(str, NULL, NULL);
+	exe = execl(str, NULL, (char *)NULL);
 	if (exe == -1 && errno != EACCES)
 		result = result + OP_EXEC;
 
testcases/open_posix_testsuite/conformance/interfaces/sem_unlink/2-2.c +1 -1
index 1e9096b23..bd8b4f92e 100644
@@ -183,7 +183,7 @@ int main(void)
 
 	if (p3 == 0) {		/* child */
 		sem = common();
-		ret = execl("/bin/ls", "ls", NULL);
+		ret = execl("/bin/ls", "ls", (char *)NULL);
 		UNRESOLVED(errno, "Failed to exec");
 	}
 
testcases/open_posix_testsuite/conformance/interfaces/sigaltstack/9-1.c +1 -1
index e9f9a8f71..aee0c9b94 100644
@@ -68,7 +68,7 @@ int main(int argc, char *argv[])
 		} else {
 			strcpy(path, argv[0]);
 		}
-		execl(path, argv[0], "verify", NULL);
+		execl(path, argv[0], "verify", (char *)NULL);
 		printf("Failed: execl() errno: %s\n", strerror(errno));
 		exit(PTS_UNRESOLVED);
 
testcases/open_posix_testsuite/conformance/interfaces/timer_create/9-1.c +1 -1
index a68879389..8c65da322 100644
@@ -71,7 +71,7 @@ int main(void)
 		return PTS_UNRESOLVED;
 	}
 
-	if (execl("/bin/sleep", "sleep", "3", NULL) == -1) {
+	if (execl("/bin/sleep", "sleep", "3", (char *)NULL) == -1) {
 		printf("Test FAILED\n");
 		return PTS_FAIL;
 	}
Signature · 5 lines
2.38.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
Quoted 5 lines · Petr Vorel

Hi David,

thanks for fixing this!

This seems to be quite a controversial topic :)

I stumbled over [1], which still left me confused regarding what to do and what to not do.

Interestingly, the problem doesn't seem to be that NULL is defined in a strange way, but that the representation of (void *)NULL and (char *)NULL might be (weirdly enough) different, and that no explicit cast could result in undefined behavior.

IIUC, the second answer indicates that with C99 it might be fine, because that case is defined behavior ("one type is pointer to void and the other is a pointer to a character type.").

Having that said, I have cannot really tell if this change must be performed. :)

[1] https://stackoverflow.com/questions/52195275/can-the-compiler-cast-void-0-in-execlprog-arg-void-0-to-a-null-po

Signature · 7 lines
Thanks,

David / dhildenb


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi Michael,

sorry to bother you, could you please comment our discussion about execl{,e,p}() termination of argument list being NULL vs. (char *)NULL vs. (void*)0?

Martin reported [2] that man page suggests (char*)NULL, his view of reason [3]:
NULL may be defined as simple integer 0. When int is 32bit and pointers 64bit, this will cause trouble in variadic functions such as execlp().

Cyril pointed out [4]: NULL is required to be 0 cast to void* in POSIX. [5]

Therefore what should be really used?

Kind regards,
Petr

[2] https://lore.kernel.org/ltp/[email protected]/
[3] https://lore.kernel.org/ltp/[email protected]/
[4] https://lore.kernel.org/ltp/Y4DSmk7uY9zUUQsV@yuki/
[5] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html

Quoted 28 lines · Petr Vorel
Quoted 5 lines

Hi David,

thanks for fixing this!

This seems to be quite a controversial topic :)

I stumbled over [1], which still left me confused regarding what to do and what to not do.

Interestingly, the problem doesn't seem to be that NULL is defined in a strange way, but that the representation of (void *)NULL and (char *)NULL might be (weirdly enough) different, and that no explicit cast could result in undefined behavior.

IIUC, the second answer indicates that with C99 it might be fine, because that case is defined behavior ("one type is pointer to void and the other is a pointer to a character type.").

Having that said, I have cannot really tell if this change must be performed. :)

[1] https://stackoverflow.com/questions/52195275/can-the-compiler-cast-void-0-in-execlprog-arg-void-0-to-a-null-po

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Acked-by
#4 lore raw
Quoted 13 lines · Petr Vorel

Hi Michael,

sorry to bother you, could you please comment our discussion about execl{,e,p}() termination of argument list being NULL vs. (char *)NULL vs. (void*)0?

Martin reported [2] that man page suggests (char*)NULL, his view of reason [3]:
NULL may be defined as simple integer 0. When int is 32bit and pointers 64bit, this will cause trouble in variadic functions such as execlp().

Cyril pointed out [4]: NULL is required to be 0 cast to void* in POSIX. [5]

Therefore what should be really used?

Quoted 7 lines

Kind regards,
Petr

[2] https://lore.kernel.org/ltp/[email protected]/
[3] https://lore.kernel.org/ltp/[email protected]/
[4] https://lore.kernel.org/ltp/Y4DSmk7uY9zUUQsV@yuki/
[5] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html

Cyril is correct that we don't need this fix as long as we use C99 or later with POSIX-compliant build system. The explicit type cast is required only in C++ where there's no explicit conversion from void* to other pointer types and therefore NULL must be defined as integer instead of void* pointer constant.

Then again, pedantically following the docs won't break anything either.

Signature · 11 lines
Martin Doucha   [email protected]
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Hello,

Quoted 26 lines · Martin Doucha
Quoted 10 lines · Petr Vorel

Hi Michael,
sorry to bother you, could you please comment our discussion about execl{,e,p}()
termination of argument list being NULL vs. (char *)NULL vs. (void*)0? Martin reported [2] that man page suggests (char*)NULL, his view of reason [3]:
NULL may be defined as simple integer 0. When int is 32bit and pointers 64bit, this will cause trouble in variadic functions such as execlp(). Cyril pointed out [4]: NULL is required to be 0 cast to void* in POSIX. [5]

Quoted 8 lines

Therefore what should be really used?
Kind regards,
Petr
[2]
https://lore.kernel.org/ltp/[email protected]/
[3] https://lore.kernel.org/ltp/[email protected]/
[4] https://lore.kernel.org/ltp/Y4DSmk7uY9zUUQsV@yuki/
[5] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html

Cyril is correct that we don't need this fix as long as we use C99 or later with POSIX-compliant build system. The explicit type cast is required only in C++ where there's no explicit conversion from void* to other pointer types and therefore NULL must be defined as integer instead of void* pointer constant.

Quoted 3 lines

Then again, pedantically following the docs won't break anything either.

I think the docs are wrong here, they should probably specify where it is needed to cast to (char *). We are (now) using a superset of c99 so we are not effected.

The issue I see is that this is yet another thing to remember to enforce and for no apparent benefit. OTOH if there is some compiler/analyser flag which creates a warning then I would not be against adding that.

Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Hello,

Quoted 34 lines · Richard Palethorpe

Hello,

Quoted 26 lines · Martin Doucha
Quoted 10 lines · Petr Vorel

Hi Michael,
sorry to bother you, could you please comment our discussion about execl{,e,p}()
termination of argument list being NULL vs. (char *)NULL vs. (void*)0? Martin reported [2] that man page suggests (char*)NULL, his view of reason [3]:
NULL may be defined as simple integer 0. When int is 32bit and pointers 64bit, this will cause trouble in variadic functions such as execlp(). Cyril pointed out [4]: NULL is required to be 0 cast to void* in POSIX. [5]

Quoted 8 lines

Therefore what should be really used?
Kind regards,
Petr
[2]
https://lore.kernel.org/ltp/[email protected]/
[3] https://lore.kernel.org/ltp/[email protected]/
[4] https://lore.kernel.org/ltp/Y4DSmk7uY9zUUQsV@yuki/
[5] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html

Cyril is correct that we don't need this fix as long as we use C99 or later with POSIX-compliant build system. The explicit type cast is required only in C++ where there's no explicit conversion from void* to other pointer types and therefore NULL must be defined as integer instead of void* pointer constant.

Quoted 3 lines

Then again, pedantically following the docs won't break anything either.

Quoted 7 lines

I think the docs are wrong here, they should probably specify where it is needed to cast to (char *). We are (now) using a superset of c99 so we are not effected.

The issue I see is that this is yet another thing to remember to enforce and for no apparent benefit. OTOH if there is some compiler/analyser flag which creates a warning then I would not be against adding that.

Setting this to Not Applicable in patchwork. This is not final, but it will remove it from the queue.

Quoted 4 lines
Signature · 3 lines
-- 
Thank you,
Richard.
Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp