]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
exec_shell: use xasprintf
authorThomas Weißschuh <thomas@t-8ch.de>
Sun, 24 Dec 2023 11:00:53 +0000 (12:00 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Sun, 31 Dec 2023 12:04:23 +0000 (13:04 +0100)
It removes an unbounded strcpy and makes the code shorter and clearer.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
lib/exec_shell.c

index 6fef6c7a326dbe5a2b2c3ec74148152afd4c1af9..96d3e95a8d1dcadf77b211a2341870a061896762 100644 (file)
@@ -42,9 +42,7 @@ void __attribute__((__noreturn__)) exec_shell(void)
 
        shellc = xstrdup(shell);
        shell_basename = basename(shellc);
-       arg0 = xmalloc(strlen(shell_basename) + 2);
-       arg0[0] = '-';
-       strcpy(arg0 + 1, shell_basename);
+       xasprintf(&arg0, "-%s", shell_basename);
 
        execl(shell, arg0, (char *)NULL);
        errexec(shell);