[PATCH] standalone shell / prefer_applets: fix comm field problem
Lukasz Serafin
Lukasz.Serafin at axis.com
Fri Apr 24 15:20:02 UTC 2020
The output of /proc/self/comm shall only be changed to the applet name
if it is "exe". It shall not be changed if it is for example the name
of a shell script.
Signed-off-by: Lukasz Serafin <lukasz.serafin at axis.com>
---
include/libbb.h | 2 ++
libbb/appletlib.c | 11 +++++++++--
libbb/vfork_daemon_rexec.c | 5 +++++
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/include/libbb.h b/include/libbb.h
index 392c0443d..2e8d7f3d0 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1177,8 +1177,10 @@ void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_
#endif
#if defined(__linux__)
void set_task_comm(const char *comm) FAST_FUNC;
+void get_task_comm(char *buffer) FAST_FUNC;
#else
# define set_task_comm(name) ((void)0)
+# define get_task_comm(name) ((void)0)
#endif
/* Helpers for daemonization.
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index f842e73cc..ad3affba4 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -33,6 +33,8 @@
# include <malloc.h> /* for mallopt */
#endif
+#define COMM_MAX_SIZE 16
+
/* Declare <applet>_main() */
#define PROTOTYPES
#include "applets.h"
@@ -1115,8 +1117,13 @@ int main(int argc UNUSED_PARAM, char **argv)
|| ENABLE_FEATURE_PREFER_APPLETS
|| !BB_MMU
) {
- if (NUM_APPLETS > 1)
- set_task_comm(applet_name);
+ if (NUM_APPLETS > 1) {
+ char buffer[COMM_MAX_SIZE];
+ buffer[0] = '\0';
+ get_task_comm(buffer);
+ if (strcmp(buffer, "exe") == 0)
+ set_task_comm(applet_name);
+ }
}
parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 65271e84f..c12173cd0 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -33,6 +33,11 @@ void FAST_FUNC set_task_comm(const char *comm)
/* okay if too long (truncates) */
prctl(PR_SET_NAME, (long)comm, 0, 0, 0);
}
+void FAST_FUNC get_task_comm(char* buffer)
+{
+ /* returned name can be up to 16 bytes long (including null byte) */
+ prctl(PR_GET_NAME, (long)buffer, 0, 0, 0);
+}
#endif
/*
--
2.11.0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20200424/35969452/attachment.html>
More information about the busybox
mailing list