diff options
author | mirabilos <tg@mirbsd.org> | 2017-11-17 22:44:48 +0100 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2017-11-19 09:09:27 +0100 |
commit | d68e2217231db1a738374dbff846a5612be621a0 (patch) | |
tree | e178ea4f32e1bc70a2f4cbf69a9c602b4b3d002a | |
parent | f75ac8152a6324e14d2708d9dc83eeb221506cf1 (diff) |
Use only safe functions after vfork(2)
Signed-off-by: mirabilos <tg@mirbsd.org>
-rw-r--r-- | package/sash/src/sash.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/package/sash/src/sash.c b/package/sash/src/sash.c index b856362ce..7fb3a39fb 100644 --- a/package/sash/src/sash.c +++ b/package/sash/src/sash.c @@ -656,6 +656,8 @@ trybuiltin(argc, argv) return TRUE; } +static const char enoent_msg[] = "Bad command or file name"; +static const char unkerr_msg[] = "Unknown error!"; /* * Execute the specified command. @@ -783,6 +785,7 @@ runcmd(cmd, bg, argc, argv) */ if (!(pid = vfork())) { int ci; + char errbuf[50]; /* * We are the child, so run the program. @@ -800,9 +803,18 @@ runcmd(cmd, bg, argc, argv) execvp(newargv[0], newargv); - printf("%s: %s\n", newargv[0], (errno == ENOENT) ? "Bad command or file name" : strerror(errno)); - - _exit(0); + ci = errno; + write(2, newargv[0], strlen(newargv[0])); + write(2, ": ", 2); + if (ci == ENOENT) + write(2, enoent_msg, sizeof(enoent_msg) - 1); + else if (strerror_r(ci, errbuf, sizeof(errbuf))) + write(2, unkerr_msg, sizeof(unkerr_msg) - 1); + else + write(2, errbuf, strlen(errbuf)); + write(2, "\n", 1); + + _exit(ci == ENOENT ? 127 : 126); } if (pid < 0) { |