From: Alejandro Colomar Date: Fri, 31 May 2024 16:30:16 +0000 (+0200) Subject: lib/idmapping.c: Use long constants in prctl(2), and remove 0s X-Git-Tag: 4.17.0-rc1~170 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=379e9c32f794adb62c22dbeca1d9cbf23d7b14d3;p=thirdparty%2Fshadow.git lib/idmapping.c: Use long constants in prctl(2), and remove 0s The prctl(2) system-call wrapper is implemented as a variadic function. This makes it important to pass arguments to it of the right type (and more importantly of the right width), to avoid undefined behavior. While at it, check errors with ==-1, not <0, which is more explicit. Also, PR_SET_KEEPCAPS(2const) doesn't need all arguments, so it can be called with just two of them; remove unnecessary 0s. See-also: prctl(2), PR_SET_KEEPCAPS(2const) Link: Cc: Xi Ruoyao Cc: Lukas Slebodnik Signed-off-by: Alejandro Colomar --- diff --git a/lib/idmapping.c b/lib/idmapping.c index fe3ccdfe3..5cbb6fefc 100644 --- a/lib/idmapping.c +++ b/lib/idmapping.c @@ -159,7 +159,7 @@ void write_mapping(int proc_dir_fd, int ranges, const struct map_range *mappings /* Align setuid- and fscaps-based new{g,u}idmap behavior. */ if (geteuid() == 0 && geteuid() != ruid) { - if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) < 0) { + if (prctl(PR_SET_KEEPCAPS, 1L) == -1) { fprintf(log_get_logfd(), _("%s: Could not prctl(PR_SET_KEEPCAPS)\n"), log_get_progname()); exit(EXIT_FAILURE); }