git: eb36277dc926 - stable/14 - posix_spawnattr_setflags(3): validate argument

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

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

commit eb36277dc926b671b520ca0ecb1da54eacf424a2
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:25:58 +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 a067d1f68ea5..41e059cf437b 100644
--- a/lib/libc/gen/posix_spawn.c
+++ b/lib/libc/gen/posix_spawn.c
@@ -629,6 +629,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 ,