Skip to content

Commit 89a8623

Browse files
src/usermod.c: $user_newhome: Remove all trailing '/'s
FTR: I'm not entirely sure if an empty string can arrive here. It might be that the streq() check is dead code, but I'm not sure, so I put it. It also makes the code more robust. Signed-off-by: Alejandro Colomar <[email protected]>
1 parent 655ffcb commit 89a8623

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/usermod.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#endif /* ACCT_TOOLS_SETUID */
2929
#include <paths.h>
3030
#include <stdio.h>
31+
#include <string.h>
3132
#include <strings.h>
3233
#include <sys/stat.h>
3334
#include <sys/types.h>
@@ -68,6 +69,7 @@
6869
#include "string/strcmp/streq.h"
6970
#include "string/strcmp/strprefix.h"
7071
#include "string/strdup/strdup.h"
72+
#include "string/strspn/stprspn.h"
7173
#include "time/day_to_str.h"
7274
#include "typetraits.h"
7375

@@ -547,10 +549,8 @@ static void new_pwent (struct passwd *pwent, bool process_selinux)
547549
"change user '%s' home from '%s' to '%s'",
548550
pwent->pw_name, pwent->pw_dir, user_newhome));
549551

550-
if (strlen(user_newhome) > 1
551-
&& '/' == user_newhome[strlen(user_newhome)-1]) {
552-
user_newhome[strlen(user_newhome)-1]='\0';
553-
}
552+
if (!streq(user_newhome, ""))
553+
stpcpy(stprspn(user_newhome + 1, "/"), "");
554554

555555
pwent->pw_dir = user_newhome;
556556
}

0 commit comments

Comments
 (0)