-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libtrace.c: use realpath instead of readlink to avoid PATH_MAX #4606
Conversation
By the way, I noticed that there is barely any dynamic memory being allocated |
I don't think there are any security or performance implications. LGTM! (If you are asking for nitpicks: I think |
@smitsohu commented on Oct 16:
Great.
Yes, especially when touching things that I don't know much about, such as
Interesting, I had no idea about this.
I see; would it be an improvement to check for ENOMEM and exit or would that diff --git a/src/libtrace/libtrace.c b/src/libtrace/libtrace.c
index 106ce99f3..98d8603f2 100644
--- a/src/libtrace/libtrace.c
+++ b/src/libtrace/libtrace.c
@@ -18,6 +18,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define _GNU_SOURCE
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -706,7 +707,11 @@ static void log_exec(int argc, char** argv) {
(void) argc;
(void) argv;
char *buf = realpath("/proc/self/exe", NULL);
- if (buf != NULL) {
+ if (buf == NULL) {
+ if (errno == ENOMEM) {
+ tprintf(ftty, "realpath: %s\n", strerror(errno));
+ exit(1);
+ }
+ } else {
tprintf(ftty, "%u:%s:exec %s:0\n", mypid, myname, buf);
free(buf);
} Besides not having to deal with Note: If the downsides of realpath are bigger than the upsides, this doesn't |
As far as I know these magic links from /proc are never longer than 4096 bytes, which is the size of a single page. People hardcode this frequently. Well... let's not complicate it too much. It looks like a simple change, whatever way you choose will be right. |
PATH_MAX is not guaranteed to be defined and it may be defined to -1. Avoid depending on it by getting the result directly from realpath. See commit 579f856 ("firejail.h: add missing linux/limits.h include") / PR netblue30#4583 for details. Note: This replaces the static char array currently used with a dynamic one returned from realpath. Misc: This is a continuation of netblue30#4583.
a77781b
to
8954cb2
Compare
@smitsohu commented on Oct 16:
Alright, I did a force-push with the changes from the diff; unless any other |
Merged. |
PATH_MAX is not guaranteed to be defined and it may be defined to -1.
Avoid depending on it by getting the result directly from realpath. See
commit 579f856 ("firejail.h: add missing linux/limits.h include") /
PR #4583 for details.
Note: This replaces the static char array currently used with a dynamic
one returned from realpath.
Misc: This is a continuation of #4583.