]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/: Use xasprintf() instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Mon, 13 May 2024 12:37:14 +0000 (14:37 +0200)
committerSerge Hallyn <serge@hallyn.com>
Tue, 2 Jul 2024 02:40:11 +0000 (21:40 -0500)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/obscure.c
src/passwd.c
src/su.c
src/usermod.c

index 549c2a8dfaddd14bf842304bca2392eba98eedbb..32e8941ce833500cb3271c42f5fccc88b19a275d 100644 (file)
@@ -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");
index 7bacfe596b71a1cbc765176631eaa9dea81114a8..e22788f5c8e25f69ae6db39c3a3333ce284f1775 100644 (file)
@@ -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) {
index 23d27f2e3485172f7c739e4d25c54c361081a82e..cfc5ab1f215a96d224a637a49a5df3efe7c0ccd2 100644 (file)
--- 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);
        }
index f05d54334ea04fb1812d1ffb2cd024aa255f06ea..1291814be33a86dc4641b8be36d196e82a339690 100644 (file)
@@ -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') {