From: Alejandro Colomar Date: Wed, 1 Jan 2025 13:02:08 +0000 (+0100) Subject: lib/, src/: Use aprintf() instead of asprintf(3) X-Git-Tag: 4.18.0-rc1~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=86303b12338355d7eae098ab2e962b859d606c93;p=thirdparty%2Fshadow.git lib/, src/: Use aprintf() instead of asprintf(3) Signed-off-by: Alejandro Colomar --- diff --git a/lib/commonio.c b/lib/commonio.c index 38bf65c59..7304ec006 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -35,6 +35,7 @@ #include "shadowlog_internal.h" #include "sssd.h" #include "string/memset/memzero.h" +#include "string/sprintf/aprintf.h" #include "string/sprintf/snprintf.h" #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" @@ -361,9 +362,12 @@ int commonio_lock_nowait (struct commonio_db *db, bool log) return 1; } - if (asprintf(&file, "%s.%ju", db->filename, (uintmax_t) getpid()) == -1) + file = aprintf("%s.%ju", db->filename, (uintmax_t) getpid()); + if (file == NULL) goto cleanup_ENOMEM; - if (asprintf(&lock, "%s.lock", db->filename) == -1) + + lock = aprintf("%s.lock", db->filename); + if (lock == NULL) goto cleanup_ENOMEM; if (do_lock_file (file, lock, log) != 0) { diff --git a/lib/copydir.c b/lib/copydir.c index 3a6c132b5..9dbe6fd6f 100644 --- a/lib/copydir.c +++ b/lib/copydir.c @@ -38,6 +38,7 @@ #include #endif /* WITH_ATTR */ #include "shadowlog.h" +#include "string/sprintf/aprintf.h" #include "string/sprintf/xasprintf.h" #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" @@ -322,13 +323,13 @@ static int copy_tree_impl (const struct path_info *src, const struct path_info * continue; } - if (asprintf(&src_name, "%s/%s", src->full_path, ent->d_name) == -1) - { + src_name = aprintf("%s/%s", src->full_path, ent->d_name); + if (src_name == NULL) { err = -1; continue; } - if (asprintf(&dst_name, "%s/%s", dst->full_path, ent->d_name) == -1) - { + dst_name = aprintf("%s/%s", dst->full_path, ent->d_name); + if (dst_name == NULL) { err = -1; goto skip; } diff --git a/lib/groupio.c b/lib/groupio.c index a4348a1c7..72391433b 100644 --- a/lib/groupio.c +++ b/lib/groupio.c @@ -23,6 +23,7 @@ #include "getdef.h" #include "groupio.h" #include "prototypes.h" +#include "string/sprintf/aprintf.h" #include "string/strcmp/streq.h" @@ -325,7 +326,8 @@ static /*@null@*/struct commonio_entry *merge_group_entries ( } /* Concatenate the 2 lines */ - if (asprintf(&new_line, "%s\n%s", gr1->line, gr2->line) == -1) + new_line = aprintf("%s\n%s", gr1->line, gr2->line); + if (new_line == NULL) return NULL; /* Concatenate the 2 list of members */ diff --git a/lib/run_part.c b/lib/run_part.c index 890f837cd..745dd354e 100644 --- a/lib/run_part.c +++ b/lib/run_part.c @@ -13,6 +13,7 @@ #include "run_part.h" #include "shadowlog_internal.h" +#include "string/sprintf/aprintf.h" static int run_part(char *script_path, const char *name, const char *action) @@ -60,8 +61,9 @@ int run_parts(const char *directory, const char *name, const char *action) char *s; struct stat sb; - if (asprintf(&s, "%s/%s", directory, namelist[n]->d_name) == -1) { - fprintf(shadow_logfd, "asprintf: %s\n", strerror(errno)); + s = aprintf("%s/%s", directory, namelist[n]->d_name); + if (s == NULL) { + fprintf(shadow_logfd, "aprintf: %s\n", strerror(errno)); for (; n