lib/, src/: Use xasprintf() instead of its pattern

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2023-10-20 21:05:33 +02:00
parent ad3b31a59e
commit d5e1c1e475
10 changed files with 50 additions and 75 deletions
+4 -5
View File
@@ -35,6 +35,7 @@
#include <attr/libattr.h>
#endif /* WITH_ATTR */
#include "shadowlog.h"
#include "sprintf.h"
static /*@null@*/const char *src_orig;
@@ -228,8 +229,7 @@ static /*@exposed@*/ /*@null@*/struct link_name *check_link (const char *name, c
lp->ln_dev = sb->st_dev;
lp->ln_ino = sb->st_ino;
lp->ln_count = sb->st_nlink;
if (asprintf(&lp->ln_name, "%s%s", dst_orig, name + strlen(src_orig)) == -1)
exit(EXIT_FAILURE);
xasprintf(&lp->ln_name, "%s%s", dst_orig, name + strlen(src_orig));
lp->ln_next = links;
links = lp;
@@ -608,11 +608,10 @@ static int copy_symlink (const struct path_info *src, const struct path_info *ds
* create a link to the corresponding entry in the dst_orig
* directory.
*/
if (strncmp (oldlink, src_orig, strlen (src_orig)) == 0) {
if (strncmp(oldlink, src_orig, strlen(src_orig)) == 0) {
char *dummy;
if (asprintf(&dummy, "%s%s", dst_orig, oldlink + strlen(src_orig)) == -1)
exit(EXIT_FAILURE);
xasprintf(&dummy, "%s%s", dst_orig, oldlink + strlen(src_orig));
free(oldlink);
oldlink = dummy;
}
+2 -2
View File
@@ -20,6 +20,7 @@
#include "prototypes.h"
#include "defines.h"
#include "shadowlog.h"
#include "sprintf.h"
/*
@@ -73,8 +74,7 @@ void addenv (const char *string, /*@null@*/const char *value)
size_t i, n;
if (NULL != value) {
if (asprintf(&newstring, "%s=%s", string, value) == -1)
exit(EXIT_FAILURE);
xasprintf(&newstring, "%s=%s", string, value);
} else {
newstring = xstrdup (string);
}
+3 -4
View File
@@ -25,6 +25,7 @@
#include "alloc.h"
#include "getdef.h"
#include "shadowlog_internal.h"
#include "sprintf.h"
/*
@@ -447,12 +448,10 @@ void setdef_config_file (const char* file)
#ifdef USE_ECONF
char *cp;
if (asprintf(&cp, "%s/%s", file, sysconfdir) == -1)
exit(13);
xasprintf(&cp, "%s/%s", file, sysconfdir);
sysconfdir = cp;
#ifdef VENDORDIR
if (asprintf(&cp, "%s/%s", file, vendordir) == -1)
exit(13);
xasprintf(&cp, "%s/%s", file, vendordir);
vendordir = cp;
#endif
#else
+2 -2
View File
@@ -17,6 +17,7 @@
#include "alloc.h"
#include "getdef.h"
#include "sprintf.h"
#ident "$Id$"
@@ -37,8 +38,7 @@ void mailcheck (void)
if (NULL != mailbox) {
char *newmail;
if (asprintf(&newmail, "%s/new", mailbox) == -1)
exit(EXIT_FAILURE);
xasprintf(&newmail, "%s/new", mailbox);
if (stat (newmail, &statbuf) != -1 && statbuf.st_size != 0) {
if (statbuf.st_mtime > statbuf.st_atime) {
+8 -14
View File
@@ -28,6 +28,7 @@
#endif /* ENABLE_SUBIDS */
#include "getdef.h"
#include "shadowlog.h"
#include "sprintf.h"
static char *passwd_db_file = NULL;
@@ -106,42 +107,35 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char **
exit (E_BAD_ARG);
}
if (asprintf(&passwd_db_file, "%s/%s", prefix, PASSWD_FILE) == -1)
exit(EXIT_FAILURE);
xasprintf(&passwd_db_file, "%s/%s", prefix, PASSWD_FILE);
pw_setdbname(passwd_db_file);
if (asprintf(&group_db_file, "%s/%s", prefix, GROUP_FILE) == -1)
exit(EXIT_FAILURE);
xasprintf(&group_db_file, "%s/%s", prefix, GROUP_FILE);
gr_setdbname(group_db_file);
#ifdef SHADOWGRP
if (asprintf(&sgroup_db_file, "%s/%s", prefix, SGROUP_FILE) == -1)
exit(EXIT_FAILURE);
xasprintf(&sgroup_db_file, "%s/%s", prefix, SGROUP_FILE);
sgr_setdbname(sgroup_db_file);
#endif
#ifdef USE_NIS
__setspNIS(0); /* disable NIS for now, at least until it is properly supporting a "prefix" */
#endif
if (asprintf(&spw_db_file, "%s/%s", prefix, SHADOW_FILE) == -1)
exit(EXIT_FAILURE);
xasprintf(&spw_db_file, "%s/%s", prefix, SHADOW_FILE);
spw_setdbname(spw_db_file);
#ifdef ENABLE_SUBIDS
if (asprintf(&suid_db_file, "%s/%s", prefix, "/etc/subuid") == -1)
exit(EXIT_FAILURE);
xasprintf(&suid_db_file, "%s/%s", prefix, "/etc/subuid");
sub_uid_setdbname(suid_db_file);
if (asprintf(&sgid_db_file, "%s/%s", prefix, "/etc/subgid") == -1)
exit(EXIT_FAILURE);
xasprintf(&sgid_db_file, "%s/%s", prefix, "/etc/subgid");
sub_gid_setdbname(sgid_db_file);
#endif
#ifdef USE_ECONF
setdef_config_file(prefix);
#else
if (asprintf(&def_conf_file, "%s/%s", prefix, "/etc/login.defs") == -1)
exit(EXIT_FAILURE);
xasprintf(&def_conf_file, "%s/%s", prefix, "/etc/login.defs");
setdef_config_file(def_conf_file);
#endif
}
+4 -5
View File
@@ -27,18 +27,17 @@
#include <pwd.h>
#include "getdef.h"
#include "shadowlog.h"
#include "sprintf.h"
#ifndef USE_PAM
static void
addenv_path (const char *varname, const char *dirname, const char *filename)
addenv_path(const char *varname, const char *dirname, const char *filename)
{
char *buf;
if (asprintf(&buf, "%s/%s", dirname, filename) == -1)
exit(EXIT_FAILURE);
addenv (varname, buf);
xasprintf(&buf, "%s/%s", dirname, filename);
addenv(varname, buf);
free(buf);
}