From: Craig Small Date: Mon, 13 Aug 2018 11:19:39 +0000 (+1000) Subject: pslog: Define PATH_MAX if required X-Git-Tag: v23.2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=74eeeff5676ecb90d7db00827b5415083d052b2c;p=psmisc pslog: Define PATH_MAX if required Hurd doesn't define PATH_MAX so we either change things to not use it or conditionally define it. References: https://bugs.debian.org/905797 --- diff --git a/ChangeLog b/ChangeLog index f7ffbf6..e9c5c11 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ Changes in 23.2 * killall: look at all namespaces by default * killall: Fix -INT option parsing #11 * killall: change to getopt_long without _only #12 + * pslog: Define PATH_MAX if required Debian:#905797 + Changes in 23.1 =============== * killall: Remove debug output Debian: #864753 diff --git a/src/pslog.c b/src/pslog.c index f661245..d60723f 100644 --- a/src/pslog.c +++ b/src/pslog.c @@ -18,6 +18,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif #include #include @@ -28,10 +31,15 @@ #include #include #include +#include #include "i18n.h" +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif /* PATH_MAX */ + static int usage () { @@ -61,6 +69,7 @@ main(int argc, char const *argv[]) { regex_t re_log; regex_t re_pid; + char *fullpath = NULL; if (argc < 2) { usage(); @@ -100,12 +109,6 @@ main(int argc, char const *argv[]) struct dirent *namelist; - char* fullpath = (char*) malloc(PATH_MAX+1); - if (!fullpath) { - perror ("malloc"); - return 1; - } - char* linkpath = (char*) malloc(PATH_MAX+1); if (!linkpath) { perror ("malloc"); @@ -117,17 +120,21 @@ main(int argc, char const *argv[]) DIR *pid_dir; if (argv[1][0] != '/') { - strncpy(fullpath, "/proc/", PATH_MAX); - strncat(fullpath, argv[1], PATH_MAX - strlen(fullpath)); - strncat(fullpath, "/fd/", PATH_MAX - strlen(fullpath)); + if (asprintf(&fullpath, "/proc/%s/fd/", argv[1]) < 0) { + perror ("asprintf"); + return 1; + } } else { - strncpy(fullpath, argv[1], PATH_MAX); - strncat(fullpath, "/fd/", PATH_MAX - strlen(fullpath)); + if (asprintf(&fullpath, "%s/fd/", argv[1]) < 0) { + perror("asprintf"); + return 1; } + } pid_dir = opendir(fullpath); if (!pid_dir) { perror("opendir"); + free(fullpath); return 1; }