]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/useradd: avoid usage of sprintf
authorChristian Göttsche <cgzones@googlemail.com>
Mon, 11 Dec 2023 16:13:43 +0000 (17:13 +0100)
committerSerge Hallyn <serge@hallyn.com>
Thu, 14 Dec 2023 13:40:40 +0000 (07:40 -0600)
sprintf(3) does not take the destination buffer into account. Although
the destination in these case is large enough, sprintf(3) indicates a
code smell.

Use the xasprintf() wrapper.

src/useradd.c

index e947361b418701240257f8698eefea86ef1a8f66..98603f98d55f638ef668df85be00206fe91845c0 100644 (file)
@@ -2387,7 +2387,6 @@ static void create_mail (void)
        char          *file;
        gid_t         gid;
        mode_t        mode;
-       size_t        size;
        const char    *spool;
        struct group  *gr;
 
@@ -2403,12 +2402,10 @@ static void create_mail (void)
        if (NULL == spool) {
                return;
        }
-       size = strlen(prefix) + strlen(spool) + strlen(user_name) + 3;
-       file = XMALLOC(size, char);
        if (prefix[0])
-               sprintf(file, "%s/%s/%s", prefix, spool, user_name);
+               xasprintf(&file, "%s/%s/%s", prefix, spool, user_name);
        else
-               sprintf(file, "%s/%s", spool, user_name);
+               xasprintf(&file, "%s/%s", spool, user_name);
 
 #ifdef WITH_SELINUX
        if (set_selinux_file_context(file, S_IFREG) != 0) {