git: 2c34a6f77008 - stable/13 - posix_spawnattr_setflags(3): validate argument

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Mon, 11 Mar 2024 00:30:31 UTC
The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=2c34a6f77008780307df85d9387adf37bf74026f

commit 2c34a6f77008780307df85d9387adf37bf74026f
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-03-03 13:19:37 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-03-11 00:29:51 +0000

    posix_spawnattr_setflags(3): validate argument
    
    (cherry picked from commit 80ac36c3a2a87a19790eba487466bf70d55f566e)
---
 lib/libc/gen/posix_spawn.c              | 4 ++++
 lib/libc/gen/posix_spawnattr_getflags.3 | 7 +++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/libc/gen/posix_spawn.c b/lib/libc/gen/posix_spawn.c
index 77f7dd9955cd..49a63bb40501 100644
--- a/lib/libc/gen/posix_spawn.c
+++ b/lib/libc/gen/posix_spawn.c
@@ -630,6 +630,10 @@ posix_spawnattr_getsigmask(const posix_spawnattr_t * __restrict sa,
 int
 posix_spawnattr_setflags(posix_spawnattr_t *sa, short flags)
 {
+	if ((flags & ~(POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP |
+	    POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER |
+	    POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK)) != 0)
+		return (EINVAL);
 	(*sa)->sa_flags = flags;
 	return (0);
 }
diff --git a/lib/libc/gen/posix_spawnattr_getflags.3 b/lib/libc/gen/posix_spawnattr_getflags.3
index 9a468cbb8b0f..18cf6683e935 100644
--- a/lib/libc/gen/posix_spawnattr_getflags.3
+++ b/lib/libc/gen/posix_spawnattr_getflags.3
@@ -83,9 +83,12 @@ The default value of this attribute is as if no flags were set.
 .Sh RETURN VALUES
 The
 .Fn posix_spawnattr_getflags
-and
+function returns zero.
+The
 .Fn posix_spawnattr_setflags
-functions return zero.
+function returns zero on success, and
+.Er EINVAL
+on failure due to invalid flag specified.
 .Sh SEE ALSO
 .Xr posix_spawn 3 ,
 .Xr posix_spawnattr_destroy 3 ,