]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/get_pid.c: Use PATH_MAX instead of a magic number
authorAlejandro Colomar <alx@kernel.org>
Fri, 6 Jun 2025 13:45:15 +0000 (15:45 +0200)
committerSerge Hallyn <serge@hallyn.com>
Sat, 7 Jun 2025 01:08:56 +0000 (20:08 -0500)
Acked-by: Lukas Slebodnik <lslebodn@fedoraproject.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/get_pid.c

index f4d31cfda14012b11aedd1419be56230b63b2502..4a0c2efac9b8116ff8eb6f22da0d3f5e19be08a4 100644 (file)
@@ -5,15 +5,14 @@
 
 #include <config.h>
 
-#ident "$Id$"
-
-#include "prototypes.h"
-#include "defines.h"
+#include <limits.h>
+#include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
 
 #include "atoi/getnum.h"
+#include "defines.h"
+#include "prototypes.h"
 #include "string/sprintf/snprintf.h"
 
 
@@ -52,13 +51,12 @@ int get_pidfd_from_fd(const char *pidfdstr)
 int open_pidfd(const char *pidstr)
 {
        int    proc_dir_fd;
-       char   proc_dir_name[32];
+       char   proc_dir_name[PATH_MAX];
        pid_t  target;
 
        if (get_pid(pidstr, &target) == -1)
                return -ENOENT;
 
-       /* max string length is 6 + 10 + 1 + 1 = 18, allocate 32 bytes */
        if (SNPRINTF(proc_dir_name, "/proc/%u/", target) == -1) {
                fprintf(stderr, "snprintf of proc path failed for %u: %s\n",
                        target, strerror(errno));