[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH] standalone shell / prefer_applets: fix comm field problem
From: Lukasz Serafin <Lukasz.Serafin () axis ! com>
Date: 2020-04-24 15:20:02
Message-ID: 0589fc2e0dc64b65b1c4548ed0c62f95 () XBOX04 ! axis ! com
[Download RAW message or body]
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@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
[Attachment #3 (text/html)]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none"><!--P{margin-top:0;margin-bottom:0;} \
--></style> </head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>The output of /proc/self/comm shall only be changed to the applet name<br>
if it is "exe". It shall not be changed if it is for example the name<br>
of a shell script.<br>
<br>
Signed-off-by: Lukasz Serafin <lukasz.serafin@axis.com><br>
---<br>
include/libbb.h \
| 2 ++<br> \
libbb/appletlib.c | 11 \
+++++++++--<br> libbb/vfork_daemon_rexec.c \
| 5 +++++<br> 3 files changed, 16 insertions(+), \
2 deletions(-)<br> <br>
diff --git a/include/libbb.h b/include/libbb.h<br>
index 392c0443d..2e8d7f3d0 100644<br>
--- a/include/libbb.h<br>
+++ b/include/libbb.h<br>
@@ -1177,8 +1177,10 @@ void run_applet_no_and_exit(int a, const char *name, char \
**argv) NORETURN FAST_<br> #endif<br>
#if defined(__linux__)<br>
void set_task_comm(const char *comm) FAST_FUNC;<br>
+void get_task_comm(char *buffer) FAST_FUNC;<br>
#else<br>
# define set_task_comm(name) ((void)0)<br>
+# define get_task_comm(name) ((void)0)<br>
#endif<br>
<br>
/* Helpers for daemonization.<br>
diff --git a/libbb/appletlib.c b/libbb/appletlib.c<br>
index f842e73cc..ad3affba4 100644<br>
--- a/libbb/appletlib.c<br>
+++ b/libbb/appletlib.c<br>
@@ -33,6 +33,8 @@<br>
# include <malloc.h> /* for mallopt */<br>
#endif<br>
<br>
+#define COMM_MAX_SIZE 16<br>
+<br>
/* Declare <applet>_main() */<br>
#define PROTOTYPES<br>
#include "applets.h"<br>
@@ -1115,8 +1117,13 @@ int main(int argc UNUSED_PARAM, char **argv)<br>
|| ENABLE_FEATURE_PREFER_APPLETS<br>
|| !BB_MMU<br>
) {<br>
- if (NUM_APPLETS > 1)<br>
- \
set_task_comm(applet_name);<br> + if \
(NUM_APPLETS > 1) {<br> + \
char buffer[COMM_MAX_SIZE];<br> + \
buffer[0] = '\0';<br> + \
get_task_comm(buffer);<br> + \
if (strcmp(buffer, "exe") == \
0)<br> + \
set_task_comm(applet_name);<br> + \
}<br> }<br>
<br>
parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG \
*/<br>
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c<br>
index 65271e84f..c12173cd0 100644<br>
--- a/libbb/vfork_daemon_rexec.c<br>
+++ b/libbb/vfork_daemon_rexec.c<br>
@@ -33,6 +33,11 @@ void FAST_FUNC set_task_comm(const char *comm)<br>
/* okay if too long (truncates) */<br>
prctl(PR_SET_NAME, (long)comm, 0, 0, 0);<br>
}<br>
+void FAST_FUNC get_task_comm(char* buffer)<br>
+{<br>
+ /* returned name can be up to 16 bytes long (including null \
byte) */<br> + prctl(PR_GET_NAME, (long)buffer, 0, 0, 0);<br>
+}<br>
#endif<br>
<br>
/*<br>
-- <br>
2.11.0<br>
<br>
</p>
</body>
</html>
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
--===============0503806619260815236==--
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic