diff options
author | smitsohu <smitsohu@gmail.com> | 2021-10-17 12:05:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-17 12:05:33 +0200 |
commit | 7adbe5f717f25927373de5f1b20d02b0184b3437 (patch) | |
tree | 35da4737198fa627b5ee00bd425fdd9af4e538c0 /src | |
parent | add /run/shm to wrc (diff) | |
parent | libtrace.c: use realpath instead of readlink to avoid PATH_MAX (diff) | |
download | firejail-7adbe5f717f25927373de5f1b20d02b0184b3437.tar.gz firejail-7adbe5f717f25927373de5f1b20d02b0184b3437.tar.zst firejail-7adbe5f717f25927373de5f1b20d02b0184b3437.zip |
Merge pull request #4606 from kmk3/rm-limits-h-libtrace
libtrace.c: use realpath instead of readlink to avoid PATH_MAX
Diffstat (limited to 'src')
-rw-r--r-- | src/libtrace/libtrace.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/libtrace/libtrace.c b/src/libtrace/libtrace.c index d88512b0a..319902ff7 100644 --- a/src/libtrace/libtrace.c +++ b/src/libtrace/libtrace.c | |||
@@ -18,12 +18,12 @@ | |||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 | */ | 19 | */ |
20 | #define _GNU_SOURCE | 20 | #define _GNU_SOURCE |
21 | #include <errno.h> | ||
21 | #include <stdio.h> | 22 | #include <stdio.h> |
22 | #include <stdlib.h> | 23 | #include <stdlib.h> |
23 | #include <string.h> | 24 | #include <string.h> |
24 | #include <dlfcn.h> | 25 | #include <dlfcn.h> |
25 | #include <sys/types.h> | 26 | #include <sys/types.h> |
26 | #include <limits.h> | ||
27 | #include <unistd.h> | 27 | #include <unistd.h> |
28 | #include <sys/socket.h> | 28 | #include <sys/socket.h> |
29 | #include <netinet/in.h> | 29 | #include <netinet/in.h> |
@@ -706,10 +706,14 @@ __attribute__((constructor)) | |||
706 | static void log_exec(int argc, char** argv) { | 706 | static void log_exec(int argc, char** argv) { |
707 | (void) argc; | 707 | (void) argc; |
708 | (void) argv; | 708 | (void) argv; |
709 | static char buf[PATH_MAX + 1]; | 709 | char *buf = realpath("/proc/self/exe", NULL); |
710 | int rv = readlink("/proc/self/exe", buf, PATH_MAX); | 710 | if (buf == NULL) { |
711 | if (rv != -1) { | 711 | if (errno == ENOMEM) { |
712 | buf[rv] = '\0'; // readlink does not add a '\0' at the end | 712 | tprintf(ftty, "realpath: %s\n", strerror(errno)); |
713 | exit(1); | ||
714 | } | ||
715 | } else { | ||
713 | tprintf(ftty, "%u:%s:exec %s:0\n", mypid, myname, buf); | 716 | tprintf(ftty, "%u:%s:exec %s:0\n", mypid, myname, buf); |
717 | free(buf); | ||
714 | } | 718 | } |
715 | } | 719 | } |