From: Alejandro Colomar Date: Mon, 13 Oct 2025 13:36:32 +0000 (+0200) Subject: src/usermod.c: $user_newhome: Remove all trailing '/'s X-Git-Tag: 4.19.0-rc1~48 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0844e244e6b455f6faf8b952105865c817cc68d1;p=thirdparty%2Fshadow.git 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 --- diff --git a/src/usermod.c b/src/usermod.c index a77344e8f..e85ffaf74 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -28,6 +28,7 @@ #endif /* ACCT_TOOLS_SETUID */ #include #include +#include #include #include #include @@ -68,6 +69,7 @@ #include "string/strcmp/strprefix.h" #include "string/strdup/strdup.h" #include "string/strerrno.h" +#include "string/strspn/stprspn.h" #include "time/day_to_str.h" #include "typetraits.h" @@ -547,10 +549,8 @@ static void new_pwent (struct passwd *pwent, bool process_selinux) "change user '%s' home from '%s' to '%s'", pwent->pw_name, pwent->pw_dir, user_newhome)); - if (strlen(user_newhome) > 1 - && '/' == user_newhome[strlen(user_newhome)-1]) { - user_newhome[strlen(user_newhome)-1]='\0'; - } + if (!streq(user_newhome, "")) + stpcpy(stprspn(user_newhome + 1, "/"), ""); pwent->pw_dir = user_newhome; }