* [musl] [PATCH] signal: check sigpause() input parameter
@ 2024-12-17 13:15 lihua.zhao.cn
2024-12-18 2:49 ` [musl] [PATCH v2] " lihua.zhao.cn
0 siblings, 1 reply; 4+ messages in thread
From: lihua.zhao.cn @ 2024-12-17 13:15 UTC (permalink / raw)
To: musl; +Cc: lihua.zhao.cn
From: Lihua Zhao <lihua.zhao.cn@windriver.com>
---
src/signal/sigpause.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/signal/sigpause.c b/src/signal/sigpause.c
index 363d2fec..a3644792 100644
--- a/src/signal/sigpause.c
+++ b/src/signal/sigpause.c
@@ -1,8 +1,13 @@
#include <signal.h>
+#include <errno.h>
int sigpause(int sig)
{
sigset_t mask;
+ if (sig < 1 || sig >= _NSIG - 1) {
+ errno = EINVAL;
+ return -1;
+ }
sigprocmask(0, 0, &mask);
sigdelset(&mask, sig);
return sigsuspend(&mask);
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [musl] [PATCH v2] signal: check sigpause() input parameter
2024-12-17 13:15 [musl] [PATCH] signal: check sigpause() input parameter lihua.zhao.cn
@ 2024-12-18 2:49 ` lihua.zhao.cn
2024-12-18 8:12 ` Markus Wichmann
0 siblings, 1 reply; 4+ messages in thread
From: lihua.zhao.cn @ 2024-12-18 2:49 UTC (permalink / raw)
To: musl; +Cc: lihua.zhao.cn
From: Lihua Zhao <lihua.zhao.cn@windriver.com>
---
src/signal/sigpause.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/signal/sigpause.c b/src/signal/sigpause.c
index 363d2fec..8bd05f58 100644
--- a/src/signal/sigpause.c
+++ b/src/signal/sigpause.c
@@ -1,8 +1,13 @@
#include <signal.h>
+#include <errno.h>
int sigpause(int sig)
{
sigset_t mask;
+ if (sig < 1 || sig >= _NSIG) {
+ errno = EINVAL;
+ return -1;
+ }
sigprocmask(0, 0, &mask);
sigdelset(&mask, sig);
return sigsuspend(&mask);
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [musl] [PATCH v2] signal: check sigpause() input parameter
2024-12-18 2:49 ` [musl] [PATCH v2] " lihua.zhao.cn
@ 2024-12-18 8:12 ` Markus Wichmann
2024-12-18 9:12 ` [musl] [PATCH v3] " lihua.zhao.cn
0 siblings, 1 reply; 4+ messages in thread
From: Markus Wichmann @ 2024-12-18 8:12 UTC (permalink / raw)
To: musl; +Cc: lihua.zhao.cn
Am Wed, Dec 18, 2024 at 10:49:52AM +0800 schrieb lihua.zhao.cn@windriver.com:
> From: Lihua Zhao <lihua.zhao.cn@windriver.com>
>
> ---
> src/signal/sigpause.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/src/signal/sigpause.c b/src/signal/sigpause.c
> index 363d2fec..8bd05f58 100644
> --- a/src/signal/sigpause.c
> +++ b/src/signal/sigpause.c
> @@ -1,8 +1,13 @@
> #include <signal.h>
> +#include <errno.h>
>
> int sigpause(int sig)
> {
> sigset_t mask;
> + if (sig < 1 || sig >= _NSIG) {
> + errno = EINVAL;
> + return -1;
> + }
> sigprocmask(0, 0, &mask);
> sigdelset(&mask, sig);
> return sigsuspend(&mask);
> --
> 2.34.1
I looked around at the competition to figure out what the concensus
seems to be on input checking. POSIX no longer specifies the function,
so that is basically all that can be done at this point.
dietlibc doesn't have this function. Neither ctags nor a fulltext search
could find it in there.
glibc and bionic both have input checking but move it into sigdelset()
(they fail the function if sigprocmask() or sigdelset() fail). musl
already has input checking in sigdelset() if that fails, so maybe a
better change would be to just use those functions instead.
int sigpause(int sig)
{
sigset_t mask;
if (sigprocmask(0, 0, &mask) || sigdelset(&mask, sig)) return -1;
return sigsuspend(&mask);
}
Ciao,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* [musl] [PATCH v3] signal: check sigpause() input parameter
2024-12-18 8:12 ` Markus Wichmann
@ 2024-12-18 9:12 ` lihua.zhao.cn
0 siblings, 0 replies; 4+ messages in thread
From: lihua.zhao.cn @ 2024-12-18 9:12 UTC (permalink / raw)
To: musl; +Cc: lihua.zhao.cn
From: Lihua Zhao <lihua.zhao.cn@windriver.com>
---
src/signal/sigpause.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/signal/sigpause.c b/src/signal/sigpause.c
index 363d2fec..b8f577ce 100644
--- a/src/signal/sigpause.c
+++ b/src/signal/sigpause.c
@@ -3,7 +3,6 @@
int sigpause(int sig)
{
sigset_t mask;
- sigprocmask(0, 0, &mask);
- sigdelset(&mask, sig);
+ if (sigprocmask(0, 0, &mask) || sigdelset(&mask, sig)) return -1;
return sigsuspend(&mask);
}
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-12-18 9:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-17 13:15 [musl] [PATCH] signal: check sigpause() input parameter lihua.zhao.cn
2024-12-18 2:49 ` [musl] [PATCH v2] " lihua.zhao.cn
2024-12-18 8:12 ` Markus Wichmann
2024-12-18 9:12 ` [musl] [PATCH v3] " lihua.zhao.cn
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).