From: Alejandro Colomar Date: Mon, 13 May 2024 12:37:14 +0000 (+0200) Subject: src/: Use xasprintf() instead of its pattern X-Git-Tag: 4.17.0-rc1~187 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d9923431eb3878243a38c7cc4e11897daebc779d;p=thirdparty%2Fshadow.git src/: Use xasprintf() instead of its pattern Signed-off-by: Alejandro Colomar --- diff --git a/lib/obscure.c b/lib/obscure.c index 549c2a8df..32e8941ce 100644 --- a/lib/obscure.c +++ b/lib/obscure.c @@ -21,6 +21,7 @@ #include "prototypes.h" #include "defines.h" #include "getdef.h" +#include "string/sprintf/xasprintf.h" #if WITH_LIBBSD == 0 #include "freezero.h" @@ -99,9 +100,7 @@ static /*@observer@*//*@null@*/const char *password_check ( newmono = str_lower (xstrdup (new)); oldmono = str_lower (xstrdup (old)); - wrapped = XMALLOC(strlen(oldmono) * 2 + 1, char); - strcpy (wrapped, oldmono); - strcat (wrapped, oldmono); + xasprintf(&wrapped, "%s%s", oldmono, oldmono); if (palindrome (oldmono, newmono)) { msg = _("a palindrome"); diff --git a/src/passwd.c b/src/passwd.c index 7bacfe596..e22788f5c 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -22,7 +22,6 @@ #include "alloc.h" #include "agetpass.h" -#include "alloc.h" #include "atoi/str2i.h" #include "defines.h" #include "getdef.h" @@ -34,6 +33,7 @@ #include "pwio.h" #include "shadowio.h" #include "shadowlog.h" +#include "string/sprintf/xasprintf.h" #include "string/strcpy/strtcpy.h" #include "time/day_to_str.h" @@ -532,10 +532,9 @@ static char *update_crypt_pw (char *cp) } if (lflg && *cp != '!') { - char *newpw = XMALLOC(strlen(cp) + 2, char); + char *newpw; - strcpy (newpw, "!"); - strcat (newpw, cp); + xasprintf(&newpw, "!%s", cp); if (!use_pam) { if (do_update_pwd) { diff --git a/src/su.c b/src/su.c index 23d27f2e3..cfc5ab1f2 100644 --- a/src/su.c +++ b/src/su.c @@ -60,6 +60,7 @@ #include "exitcodes.h" #include "shadowlog.h" #include "string/sprintf/snprintf.h" +#include "string/sprintf/xasprintf.h" #include "string/strcpy/strtcpy.h" @@ -1201,17 +1202,14 @@ int main (int argc, char **argv) * case they will be provided to the new user's shell as arguments. */ if (fakelogin) { - char *arg0; + char *arg0; cp = getdef_str ("SU_NAME"); if (NULL == cp) { cp = Basename (shellstr); } - arg0 = XMALLOC(strlen(cp) + 2, char); - arg0[0] = '-'; - strcpy (arg0 + 1, cp); - cp = arg0; + xasprintf(&arg0, "-%s", cp); } else { cp = Basename (shellstr); } diff --git a/src/usermod.c b/src/usermod.c index f05d54334..1291814be 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -412,15 +412,14 @@ usage (int status) static char *new_pw_passwd (char *pw_pass) { if (Lflg && ('!' != pw_pass[0])) { - char *buf = XMALLOC(strlen(pw_pass) + 2, char); + char *buf; #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "updating passwd", user_newname, user_newid, 0); #endif SYSLOG ((LOG_INFO, "lock user '%s' password", user_newname)); - strcpy (buf, "!"); - strcat (buf, pw_pass); + xasprintf(&buf, "!%s", pw_pass); pw_pass = buf; } else if (Uflg && pw_pass[0] == '!') { if (pw_pass[1] == '\0') {