Source: psmisc Version: 22.21-2 Severity: important Tags: patch User: debian-h...@lists.debian.org Usertags: hurd
Hi, Currently the latest version of psmisc fails to build from source and is flagged as out-of-date. This is due to usage of PATH_MAX, which is not defined on GNU/Hurd. The attached patch solve this problem by dynamically allocating space for the string 'path' in function get_threadname() of src/pstree.c and freeing it when not needed any longer. Thanks!
Index: psmisc-22.21/src/pstree.c =================================================================== --- psmisc-22.21.orig/src/pstree.c +++ psmisc-22.21/src/pstree.c @@ -797,14 +797,21 @@ static char* get_threadname(const pid_t { FILE *file; char *thread_comm, *endcomm, *threadname; - char path[PATH_MAX + 1]; + char *path = NULL; + size_t len; + int nbytes; char readbuf[BUFSIZ + 1]; if (! (threadname = malloc(COMM_LEN + 2 + 1))) { exit(2); } - if (snprintf(path, PATH_MAX, "%s/%d/task/%d/stat", PROC_BASE, pid, tid) < 0) - perror("get_threadname: asprintf"); + len = strlen(PROC_BASE) + 1 + 11 + 6 + 11 + 5 + 1; + if (! (path = malloc(len))) { + exit(2); + } + nbytes = snprintf(path, len, "%s/%d/task/%d/stat", PROC_BASE, pid, tid); + if (nbytes < 0 || nbytes >= len) + perror("get_threadname: snprintf"); if ( (file = fopen(path, "r")) != NULL) { if (fread(readbuf, 1, BUFSIZ, file) > 0) { if ((thread_comm = strchr(readbuf, '(')) @@ -813,12 +820,14 @@ static char* get_threadname(const pid_t *endcomm = '\0'; sprintf(threadname, "{%.*s}", COMM_LEN, thread_comm); (void) fclose(file); + free(path); return threadname; } } } /* Fall back to old method */ sprintf(threadname, "{%.*s}", COMM_LEN, comm); + free(path); fclose(file); return threadname; }