From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Subject: [musl] Namespace violation in system()?
Date: Thu, 4 May 2023 18:33:27 +0200 [thread overview]
Message-ID: <ZFPeVxdqNroBcFeB@voyager> (raw)
Hi all,
I stumbled upon the source code of system() today. It is this at the
moment:
|int system(const char *cmd)
|{
| pid_t pid;
| sigset_t old, reset;
| struct sigaction sa = { .sa_handler = SIG_IGN }, oldint, oldquit;
| int status = -1, ret;
| posix_spawnattr_t attr;
|
| pthread_testcancel();
|
| if (!cmd) return 1;
|
| sigaction(SIGINT, &sa, &oldint);
| sigaction(SIGQUIT, &sa, &oldquit);
| sigaddset(&sa.sa_mask, SIGCHLD);
| sigprocmask(SIG_BLOCK, &sa.sa_mask, &old);
|
| sigemptyset(&reset);
| if (oldint.sa_handler != SIG_IGN) sigaddset(&reset, SIGINT);
| if (oldquit.sa_handler != SIG_IGN) sigaddset(&reset, SIGQUIT);
| posix_spawnattr_init(&attr);
| posix_spawnattr_setsigmask(&attr, &old);
| posix_spawnattr_setsigdefault(&attr, &reset);
| posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGDEF|POSIX_SPAWN_SETSIGMASK);
| ret = posix_spawn(&pid, "/bin/sh", 0, &attr,
| (char *[]){"sh", "-c", (char *)cmd, 0}, __environ);
| posix_spawnattr_destroy(&attr);
|
| if (!ret) while (waitpid(pid, &status, 0)<0 && errno == EINTR);
| sigaction(SIGINT, &oldint, NULL);
| sigaction(SIGQUIT, &oldquit, NULL);
| sigprocmask(SIG_SETMASK, &old, NULL);
|
| if (ret) errno = ret;
| return status;
|}
Aren't all of those calls namespace violations? system() is an ISO-C
function, so the only symbols it is allowed to pull into the link are
other ISO-C functions or hidden double-underscore symbols, right? But
all the functions called here POSIX functions. And while POSIX contains
the rule that posix_* functions are reserved, that is in POSIX, not
ISO-C. And even with that rule, there are all the other calls.
Does someone need to pour out a bucket of underscores over this
function?
Ciao,
Markus
next reply other threads:[~2023-05-04 16:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-04 16:33 Markus Wichmann [this message]
2023-05-04 17:52 ` Rich Felker
2023-05-04 18:53 ` Petr Skocik
2023-05-04 19:16 ` Rich Felker
2023-05-04 19:12 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZFPeVxdqNroBcFeB@voyager \
--to=nullplan@gmx.net \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).