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:
+11
-14
@@ -63,6 +63,7 @@
|
||||
#include "tcbfuncs.h"
|
||||
#endif
|
||||
#include "shadowlog.h"
|
||||
#include "sprintf.h"
|
||||
|
||||
|
||||
#ifndef SKEL_DIR
|
||||
@@ -440,11 +441,10 @@ static void get_defaults (void)
|
||||
}
|
||||
|
||||
if (prefix[0]) {
|
||||
char *_def_template; /* avoid const warning */
|
||||
char *dt; /* avoid const warning */
|
||||
|
||||
if (asprintf(&_def_template, "%s/%s", prefix, cp) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
def_template = _def_template;
|
||||
xasprintf(&dt, "%s/%s", prefix, cp);
|
||||
def_template = dt;
|
||||
} else {
|
||||
def_template = xstrdup(cp);
|
||||
}
|
||||
@@ -459,11 +459,10 @@ static void get_defaults (void)
|
||||
}
|
||||
|
||||
if (prefix[0]) {
|
||||
char *_def_usrtemplate; /* avoid const warning */
|
||||
char *dut; /* avoid const warning */
|
||||
|
||||
if (asprintf(&_def_usrtemplate, "%s/%s", prefix, cp) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
def_usrtemplate = _def_usrtemplate;
|
||||
xasprintf(&dut, "%s/%s", prefix, cp);
|
||||
def_usrtemplate = dut;
|
||||
} else {
|
||||
def_usrtemplate = xstrdup(cp);
|
||||
}
|
||||
@@ -1582,16 +1581,14 @@ static void process_flags (int argc, char **argv)
|
||||
if (!dflg) {
|
||||
char *uh;
|
||||
|
||||
if (asprintf(&uh, "%s/%s", def_home, user_name) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&uh, "%s/%s", def_home, user_name);
|
||||
user_home = uh;
|
||||
}
|
||||
if (prefix[0]) {
|
||||
char *p_u_h; /* to avoid const warning */
|
||||
char *puh; /* to avoid const warning */
|
||||
|
||||
if (asprintf(&p_u_h, "%s/%s", prefix, user_home) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
prefix_user_home = p_u_h;
|
||||
xasprintf(&puh, "%s/%s", prefix, user_home);
|
||||
prefix_user_home = puh;
|
||||
} else {
|
||||
prefix_user_home = user_home;
|
||||
}
|
||||
|
||||
+4
-6
@@ -52,6 +52,7 @@
|
||||
#include "subordinateio.h"
|
||||
#endif /* ENABLE_SUBIDS */
|
||||
#include "shadowlog.h"
|
||||
#include "sprintf.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -804,11 +805,9 @@ static int remove_mailbox (void)
|
||||
}
|
||||
|
||||
if (prefix[0]) {
|
||||
if (asprintf(&mailfile, "%s/%s/%s", prefix, maildir, user_name) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&mailfile, "%s/%s/%s", prefix, maildir, user_name);
|
||||
} else {
|
||||
if (asprintf(&mailfile, "%s/%s", maildir, user_name) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&mailfile, "%s/%s", maildir, user_name);
|
||||
}
|
||||
|
||||
if (access (mailfile, F_OK) != 0) {
|
||||
@@ -1119,8 +1118,7 @@ int main (int argc, char **argv)
|
||||
user_gid = pwd->pw_gid;
|
||||
|
||||
if (prefix[0]) {
|
||||
if (asprintf(&user_home, "%s/%s", prefix, pwd->pw_dir) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&user_home, "%s/%s", prefix, pwd->pw_dir);
|
||||
} else {
|
||||
user_home = xstrdup(pwd->pw_dir);
|
||||
}
|
||||
|
||||
+10
-21
@@ -58,6 +58,7 @@
|
||||
#include "tcbfuncs.h"
|
||||
#endif
|
||||
#include "shadowlog.h"
|
||||
#include "sprintf.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -1266,18 +1267,12 @@ static void process_flags (int argc, char **argv)
|
||||
user_newgid = user_gid;
|
||||
}
|
||||
if (prefix[0]) {
|
||||
if (asprintf(&prefix_user_home, "%s/%s", prefix, user_home) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&prefix_user_home, "%s/%s", prefix, user_home);
|
||||
if (user_newhome) {
|
||||
if (asprintf(&prefix_user_newhome, "%s/%s",
|
||||
prefix, user_newhome) == -1)
|
||||
{
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
xasprintf(&prefix_user_newhome, "%s/%s",
|
||||
prefix, user_newhome);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
prefix_user_home = user_home;
|
||||
prefix_user_newhome = user_newhome;
|
||||
}
|
||||
@@ -2063,11 +2058,9 @@ static void move_mailbox (void)
|
||||
* between stat and chown). --marekm
|
||||
*/
|
||||
if (prefix[0]) {
|
||||
if (asprintf(&mailfile, "%s/%s/%s", prefix, maildir, user_name) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&mailfile, "%s/%s/%s", prefix, maildir, user_name);
|
||||
} else {
|
||||
if (asprintf(&mailfile, "%s/%s", maildir, user_name) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&mailfile, "%s/%s", maildir, user_name);
|
||||
}
|
||||
|
||||
fd = open (mailfile, O_RDONLY | O_NONBLOCK, 0);
|
||||
@@ -2112,14 +2105,10 @@ static void move_mailbox (void)
|
||||
char *newmailfile;
|
||||
|
||||
if (prefix[0]) {
|
||||
if (asprintf(&newmailfile, "%s/%s/%s",
|
||||
prefix, maildir, user_newname) == -1)
|
||||
{
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
xasprintf(&newmailfile, "%s/%s/%s",
|
||||
prefix, maildir, user_newname);
|
||||
} else {
|
||||
if (asprintf(&newmailfile, "%s/%s", maildir, user_newname) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&newmailfile, "%s/%s", maildir, user_newname);
|
||||
}
|
||||
if ( (link (mailfile, newmailfile) != 0)
|
||||
|| (unlink (mailfile) != 0)) {
|
||||
|
||||
+2
-2
@@ -43,6 +43,7 @@
|
||||
#include "tcbfuncs.h"
|
||||
#endif /* WITH_TCB */
|
||||
#include "shadowlog.h"
|
||||
#include "sprintf.h"
|
||||
|
||||
|
||||
#define MSG_WARN_EDIT_OTHER_FILE _( \
|
||||
@@ -304,8 +305,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (asprintf(&buf, "%s %s", editor, fileedit) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&buf, "%s %s", editor, fileedit);
|
||||
|
||||
status = system (buf);
|
||||
if (-1 == status) {
|
||||
|
||||
Reference in New Issue
Block a user