Fix execl(3) sentinel undefined behaviour.
execl(3) and its variants use a sentinel to terminate the variadic argument list, in the form of a null pointer constant of type pointer to char. POSIX mandates that NULL is a null pointer constant of type pointer to void, which is not of an equivalent type to that required by execl(3) and its variants, resulting in undefined behaviour. This commit casts all such instances of NULL to pointer to char type. For consistency, it also adds const-qualification to any such instances which had already been casted, and were not const-qualified.
This commit is contained in:
parent
6907109b7e
commit
5d774cce1d
|
@ -91,13 +91,13 @@ bool dispd_session_setup_game_rgba(struct dispd_session* session)
|
|||
const char* chvideomode = "chvideomode";
|
||||
#if 1
|
||||
// TODO chvideomode currently launches --bpp 32 as a program...
|
||||
execlp(chvideomode, chvideomode, NULL);
|
||||
execlp(chvideomode, chvideomode, (const char*) NULL);
|
||||
#else
|
||||
execlp(chvideomode, chvideomode,
|
||||
"--bpp", "32",
|
||||
"--show-graphics", "true",
|
||||
"--show-text", "false",
|
||||
NULL);
|
||||
(const char*) NULL);
|
||||
#endif
|
||||
perror(chvideomode);
|
||||
exit(127);
|
||||
|
|
|
@ -395,7 +395,7 @@ static void set_kblayout(void)
|
|||
return warning("unable to set keyboard layout: fork: %m");
|
||||
if ( !child_pid )
|
||||
{
|
||||
execlp("chkblayout", "chkblayout", "--", kblayout, (char*) NULL);
|
||||
execlp("chkblayout", "chkblayout", "--", kblayout, (const char*) NULL);
|
||||
warning("setting keyboard layout: chkblayout: %m");
|
||||
_exit(127);
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ FILE* popen(const char* command, const char* type)
|
|||
close(pipefds[unused_end]) )
|
||||
_exit(127);
|
||||
|
||||
execlp("sh", "sh", "-c", command, NULL);
|
||||
execlp("sh", "sh", "-c", command, (const char*) NULL);
|
||||
_exit(127);
|
||||
|
||||
cleanup_pipes:
|
||||
|
|
|
@ -39,6 +39,6 @@ int system(const char* command)
|
|||
return ret_error;
|
||||
return status;
|
||||
}
|
||||
execlp("sh", "sh", "-c", command, NULL);
|
||||
execlp("sh", "sh", "-c", command, (const char*) NULL);
|
||||
_exit(exit_error);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ bool is_existing_shell(const char* candidate)
|
|||
open("/dev/null", O_RDONLY);
|
||||
open("/dev/null", O_WRONLY);
|
||||
open("/dev/null", O_WRONLY);
|
||||
execlp("which", "which", "--", candidate, (char*) NULL);
|
||||
execlp("which", "which", "--", candidate, (const char*) NULL);
|
||||
exit(127);
|
||||
}
|
||||
int status;
|
||||
|
|
2
sh/sh.c
2
sh/sh.c
|
@ -1299,7 +1299,7 @@ struct execute_result execute(char** tokens,
|
|||
if ( interactive && errno == ENOENT )
|
||||
{
|
||||
int errno_saved = errno;
|
||||
execlp("command-not-found", "command-not-found", argv[0], NULL);
|
||||
execlp("command-not-found", "command-not-found", argv[0], (const char*) NULL);
|
||||
errno = errno_saved;
|
||||
}
|
||||
|
||||
|
|
|
@ -193,7 +193,7 @@ static void ExecuteFile(const char* path, int curdirfd)
|
|||
if ( ForkAndWait() )
|
||||
{
|
||||
fchdir(curdirfd);
|
||||
execl(path, path, (char*) NULL);
|
||||
execl(path, path, (const char*) NULL);
|
||||
_exit(127);
|
||||
}
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ static void DisplayFile(const char* path, int curdirfd)
|
|||
if ( ForkAndWait() )
|
||||
{
|
||||
fchdir(curdirfd);
|
||||
execlp("editor", "editor", path, (char*) NULL);
|
||||
execlp("editor", "editor", path, (const char*) NULL);
|
||||
_exit(127);
|
||||
}
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ static void ExecutePath(const char* path, int curdirfd)
|
|||
if ( ForkAndWait() )
|
||||
{
|
||||
fchdir(curdirfd);
|
||||
execlp(path, path, (char*) NULL);
|
||||
execlp(path, path, (const char*) NULL);
|
||||
_exit(127);
|
||||
}
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ void ExecuteShellCommand(const char* command, int curdirfd)
|
|||
if ( ForkAndWait() )
|
||||
{
|
||||
fchdir(curdirfd);
|
||||
execlp("sh", "sh", "-c", command, (char*) NULL);
|
||||
execlp("sh", "sh", "-c", command, (const char*) NULL);
|
||||
error(127, errno, "`%s'", "sh");
|
||||
}
|
||||
unsigned int cur_termmode;
|
||||
|
@ -505,7 +505,7 @@ private:
|
|||
|
||||
void exec_program::invoke()
|
||||
{
|
||||
execlp(program, program, (char*) NULL);
|
||||
execlp(program, program, (const char*) NULL);
|
||||
}
|
||||
|
||||
class development : public object
|
||||
|
|
|
@ -52,8 +52,8 @@ int main(void)
|
|||
dup2(pipe_fds[0], 0);
|
||||
close(pipe_fds[0]);
|
||||
close(pipe_fds[1]);
|
||||
execlp("column", "column", NULL);
|
||||
execlp("cat", "cat", NULL);
|
||||
execlp("column", "column", (const char*) NULL);
|
||||
execlp("cat", "cat", (const char*) NULL);
|
||||
int ic;
|
||||
while ( (ic = fgetc(stdin)) != EOF )
|
||||
fputc(ic, stdout);
|
||||
|
|
Loading…
Reference in New Issue