From 80ac36c3a2a87a19790eba487466bf70d55f566e Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Sun, 3 Mar 2024 15:19:37 +0200 Subject: [PATCH] posix_spawnattr_setflags(3): validate argument Reviewed by: emaste, kevans Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D44195 --- 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 ,