mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Tudor Cretu <tudor.cretu@arm.com>
To: musl@lists.openwall.com
Cc: Tudor Cretu <tudor.cretu@arm.com>
Subject: [musl] [PATCH] clone: Return EINVAL for null stack
Date: Tue,  2 Aug 2022 12:30:36 +0100	[thread overview]
Message-ID: <20220802113036.302819-1-tudor.cretu@arm.com> (raw)

This change aligns the clone wrapper with the man page. If the stack is
null, clone sets errno to EINVAL, instead of throwing a segmentation fault.
---
 src/linux/clone.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/linux/clone.c b/src/linux/clone.c
index 8c1af7d3..43a6803b 100644
--- a/src/linux/clone.c
+++ b/src/linux/clone.c
@@ -1,4 +1,5 @@
 #define _GNU_SOURCE
+#include <errno.h>
 #include <stdarg.h>
 #include <unistd.h>
 #include <sched.h>
@@ -11,6 +12,10 @@ int clone(int (*func)(void *), void *stack, int flags, void *arg, ...)
 	pid_t *ptid, *ctid;
 	void  *tls;
 
+	if (!stack) {
+		return __syscall_ret(-EINVAL);
+	}
+
 	va_start(ap, arg);
 	ptid = va_arg(ap, pid_t *);
 	tls  = va_arg(ap, void *);
-- 
2.25.1


             reply	other threads:[~2022-08-02 11:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-02 11:30 Tudor Cretu [this message]
2022-08-02 18:53 ` Rich Felker
2022-08-03 14:42   ` Tudor Cretu
2022-08-03 16:42     ` 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=20220802113036.302819-1-tudor.cretu@arm.com \
    --to=tudor.cretu@arm.com \
    --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).