]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - login-utils/su-common.c
login-utils: include libgen.h for basename API
[thirdparty/util-linux.git] / login-utils / su-common.c
index c5c0102e5ea9047997f082c9f026e32a6c886460..06ce5dba2e1b638f527cd70f69386d455dc387e5 100644 (file)
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 #include <pwd.h>
 #include <grp.h>
+#include <libgen.h>
 #include <security/pam_appl.h>
 #ifdef HAVE_SECURITY_PAM_MISC_H
 # include <security/pam_misc.h>
@@ -840,17 +841,20 @@ static void run_shell(
                                su->simulate_login ? " login" : "",
                                su->fast_startup ? " fast-start" : ""));
 
+  char* tmp = xstrdup(shell);
        if (su->simulate_login) {
                char *arg0;
                char *shell_basename;
 
-               shell_basename = basename(shell);
+               shell_basename = basename(tmp);
                arg0 = xmalloc(strlen(shell_basename) + 2);
                arg0[0] = '-';
                strcpy(arg0 + 1, shell_basename);
                args[0] = arg0;
-       } else
-               args[0] = basename(shell);
+       } else {
+    args[0] = basename(tmp);
+  }
+  free(tmp);
 
        if (su->fast_startup)
                args[argno++] = "-f";