Use _exit in child after fork, from Yayo Razo in GitHub issue 5376.

This commit is contained in:
nicm
2026-07-12 20:35:52 +00:00
committed by tmux update bot
parent 3612a9a605
commit 0925c9846b
2 changed files with 17 additions and 12 deletions

11
cmd.c
View File

@@ -1,4 +1,4 @@
/* $OpenBSD: cmd.c,v 1.185 2026/06/26 14:40:30 nicm Exp $ */ /* $OpenBSD: cmd.c,v 1.186 2026/07/12 20:35:52 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -846,7 +846,7 @@ cmd_template_replace(const char *template, const char *s, int idx)
char ch, *buf; char ch, *buf;
const char *ptr, *cp, quote[] = "\"\\$;~"; const char *ptr, *cp, quote[] = "\"\\$;~";
int replaced, quoted; int replaced, quoted;
size_t len; size_t len, slen;
if (strchr(template, '%') == NULL) if (strchr(template, '%') == NULL)
return (xstrdup(template)); return (xstrdup(template));
@@ -871,7 +871,10 @@ cmd_template_replace(const char *template, const char *s, int idx)
if (quoted) if (quoted)
ptr++; ptr++;
buf = xrealloc(buf, len + (strlen(s) * 3) + 1); slen = strlen(s);
if (slen > SIZE_MAX / 3 || len > SIZE_MAX - (slen * 3) - 1)
fatalx("argument too long");
buf = xrealloc(buf, len + (slen * 3) + 1);
for (cp = s; *cp != '\0'; cp++) { for (cp = s; *cp != '\0'; cp++) {
if (quoted && strchr(quote, *cp) != NULL) if (quoted && strchr(quote, *cp) != NULL)
buf[len++] = '\\'; buf[len++] = '\\';
@@ -880,6 +883,8 @@ cmd_template_replace(const char *template, const char *s, int idx)
buf[len] = '\0'; buf[len] = '\0';
continue; continue;
} }
if (len > SIZE_MAX - 2)
fatalx("argument too long");
buf = xrealloc(buf, len + 2); buf = xrealloc(buf, len + 2);
buf[len++] = ch; buf[len++] = ch;
buf[len] = '\0'; buf[len] = '\0';

18
job.c
View File

@@ -1,4 +1,4 @@
/* $OpenBSD: job.c,v 1.74 2025/09/08 11:21:56 nicm Exp $ */ /* $OpenBSD: job.c,v 1.75 2026/07/12 20:35:52 nicm Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -149,7 +149,7 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e,
else if (chdir("/") == 0) else if (chdir("/") == 0)
environ_set(env, "PWD", 0, "/"); environ_set(env, "PWD", 0, "/");
else else
fatal("chdir failed"); _exit(1);
} }
environ_push(env); environ_push(env);
@@ -157,21 +157,21 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e,
if (~flags & JOB_PTY) { if (~flags & JOB_PTY) {
if (dup2(out[1], STDIN_FILENO) == -1) if (dup2(out[1], STDIN_FILENO) == -1)
fatal("dup2 failed"); _exit(1);
do_close = do_close && out[1] != STDIN_FILENO; do_close = do_close && out[1] != STDIN_FILENO;
if (dup2(out[1], STDOUT_FILENO) == -1) if (dup2(out[1], STDOUT_FILENO) == -1)
fatal("dup2 failed"); _exit(1);
do_close = do_close && out[1] != STDOUT_FILENO; do_close = do_close && out[1] != STDOUT_FILENO;
if (flags & JOB_SHOWSTDERR) { if (flags & JOB_SHOWSTDERR) {
if (dup2(out[1], STDERR_FILENO) == -1) if (dup2(out[1], STDERR_FILENO) == -1)
fatal("dup2 failed"); _exit(1);
do_close = do_close && out[1] != STDERR_FILENO; do_close = do_close && out[1] != STDERR_FILENO;
} else { } else {
nullfd = open(_PATH_DEVNULL, O_RDWR); nullfd = open(_PATH_DEVNULL, O_RDWR);
if (nullfd == -1) if (nullfd == -1)
fatal("open failed"); _exit(1);
if (dup2(nullfd, STDERR_FILENO) == -1) if (dup2(nullfd, STDERR_FILENO) == -1)
fatal("dup2 failed"); _exit(1);
if (nullfd != STDERR_FILENO) if (nullfd != STDERR_FILENO)
close(nullfd); close(nullfd);
} }
@@ -185,11 +185,11 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e,
if (flags & JOB_DEFAULTSHELL) if (flags & JOB_DEFAULTSHELL)
setenv("SHELL", shell, 1); setenv("SHELL", shell, 1);
execl(shell, argv0, "-c", cmd, (char *)NULL); execl(shell, argv0, "-c", cmd, (char *)NULL);
fatal("execl failed"); _exit(1);
} else { } else {
argvp = cmd_copy_argv(argc, argv); argvp = cmd_copy_argv(argc, argv);
execvp(argvp[0], argvp); execvp(argvp[0], argvp);
fatal("execvp failed"); _exit(1);
} }
} }