summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTobias Stoeckmann2017-09-25 21:55:34 +0200
committerKarel Zak2017-09-26 12:04:41 +0200
commitc7f87da2ba6b1e0bfcd3a41737483100010778d4 (patch)
tree3ceed6ce3a6e5ea7485ea871e2bd5f96dbfec985 /lib
parentlogin: fix signal race (diff)
downloadkernel-qcow2-util-linux-c7f87da2ba6b1e0bfcd3a41737483100010778d4.tar.gz
kernel-qcow2-util-linux-c7f87da2ba6b1e0bfcd3a41737483100010778d4.tar.xz
kernel-qcow2-util-linux-c7f87da2ba6b1e0bfcd3a41737483100010778d4.zip
setproctitle: fix out of boundary access
A program using setproctitle can trigger an out of boundary access if an attacker was able to clear the environment before execution. The check in setproctitle prevents overflows, but does not take into account that the whole length of the arguments could be 1, which is possible by supplying such a program name to execlp(3) or using a symbolic link, e.g. argv[0] = "l", argv[1] = NULL. Only login uses setproctitle, which is not affected by this problem due to initializing the environment right before the call.
Diffstat (limited to 'lib')
-rw-r--r--lib/setproctitle.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/setproctitle.c b/lib/setproctitle.c
index 93bc82e47..7168e4658 100644
--- a/lib/setproctitle.c
+++ b/lib/setproctitle.c
@@ -17,7 +17,7 @@
extern char **environ;
static char **argv0;
-static int argv_lth;
+static size_t argv_lth;
void initproctitle (int argc, char **argv)
{
@@ -42,16 +42,17 @@ void initproctitle (int argc, char **argv)
return;
environ[i] = NULL;
- argv0 = argv;
if (i > 0)
- argv_lth = envp[i-1] + strlen(envp[i-1]) - argv0[0];
+ argv_lth = envp[i-1] + strlen(envp[i-1]) - argv[0];
else
- argv_lth = argv0[argc-1] + strlen(argv0[argc-1]) - argv0[0];
+ argv_lth = argv[argc-1] + strlen(argv[argc-1]) - argv[0];
+ if (argv_lth > 1)
+ argv0 = argv;
}
void setproctitle (const char *prog, const char *txt)
{
- int i;
+ size_t i;
char buf[SPT_BUFSIZE];
if (!argv0)