* src/useradd.c: Check assumptions on snprintf().
* src/useradd.c: Replace peror by an strerror and avoid an intermediate buffer. * src/useradd.c: Save errno between the failure and the report by perror/strerror. * src/useradd.c: Prefer xmalloc to malloc.
This commit is contained in:
parent
861773bf77
commit
1a87c69854
@ -1,3 +1,12 @@
|
|||||||
|
2009-04-25 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
* src/useradd.c: Check assumptions on snprintf().
|
||||||
|
* src/useradd.c: Replace peror by an strerror and avoid an
|
||||||
|
intermediate buffer.
|
||||||
|
* src/useradd.c: Save errno between the failure and the report by
|
||||||
|
perror/strerror.
|
||||||
|
* src/useradd.c: Prefer xmalloc to malloc.
|
||||||
|
|
||||||
2009-04-25 Nicolas François <nicolas.francois@centraliens.net>
|
2009-04-25 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* src/lastlog.c: Remove function calls from within assert().
|
* src/lastlog.c: Remove function calls from within assert().
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
#endif /* USE_PAM */
|
#endif /* USE_PAM */
|
||||||
#endif /* ACCT_TOOLS_SETUID */
|
#endif /* ACCT_TOOLS_SETUID */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -419,10 +420,11 @@ static int set_defaults (void)
|
|||||||
{
|
{
|
||||||
FILE *ifp;
|
FILE *ifp;
|
||||||
FILE *ofp;
|
FILE *ofp;
|
||||||
char buf[1024];
|
char buf[PATH_MAX];
|
||||||
static char new_file[] = NEW_USER_FILE;
|
static char new_file[] = NEW_USER_FILE;
|
||||||
char *cp;
|
char *cp;
|
||||||
int ofd;
|
int ofd;
|
||||||
|
int wlen;
|
||||||
bool out_group = false;
|
bool out_group = false;
|
||||||
bool out_home = false;
|
bool out_home = false;
|
||||||
bool out_inactive = false;
|
bool out_inactive = false;
|
||||||
@ -533,10 +535,13 @@ static int set_defaults (void)
|
|||||||
/*
|
/*
|
||||||
* Rename the current default file to its backup name.
|
* Rename the current default file to its backup name.
|
||||||
*/
|
*/
|
||||||
snprintf (buf, sizeof buf, "%s-", def_file);
|
wlen = snprintf (buf, sizeof buf, "%s-", def_file);
|
||||||
|
assert (wlen < sizeof buf);
|
||||||
if ((rename (def_file, buf) != 0) && (ENOENT != errno)) {
|
if ((rename (def_file, buf) != 0) && (ENOENT != errno)) {
|
||||||
snprintf (buf, sizeof buf, _("%s: rename: %s"), Prog, def_file);
|
int err = errno;
|
||||||
perror (buf);
|
fprintf (stderr,
|
||||||
|
_("%s: rename: %s: %s"),
|
||||||
|
Prog, def_file, strerror (err));
|
||||||
unlink (new_file);
|
unlink (new_file);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -545,8 +550,10 @@ static int set_defaults (void)
|
|||||||
* Rename the new default file to its correct name.
|
* Rename the new default file to its correct name.
|
||||||
*/
|
*/
|
||||||
if (rename (new_file, def_file) != 0) {
|
if (rename (new_file, def_file) != 0) {
|
||||||
snprintf (buf, sizeof buf, _("%s: rename: %s"), Prog, new_file);
|
int err = errno;
|
||||||
perror (buf);
|
fprintf (stderr,
|
||||||
|
_("%s: rename: %s: %s"),
|
||||||
|
Prog, new_file, strerror (err));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#ifdef WITH_AUDIT
|
#ifdef WITH_AUDIT
|
||||||
@ -1268,10 +1275,13 @@ static void process_flags (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
if (!dflg) {
|
if (!dflg) {
|
||||||
char *uh;
|
char *uh;
|
||||||
|
size_t len = strlen (def_home) + strlen (user_name) + 2;
|
||||||
|
int wlen;
|
||||||
|
|
||||||
|
uh = xmalloc (len);
|
||||||
|
wlen = snprintf (uh, len, "%s/%s", def_home, user_name);
|
||||||
|
assert (wlen == (int) len -1);
|
||||||
|
|
||||||
uh = xmalloc (strlen (def_home) +
|
|
||||||
strlen (user_name) + 2);
|
|
||||||
sprintf (uh, "%s/%s", def_home, user_name);
|
|
||||||
user_home = uh;
|
user_home = uh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1841,7 +1851,7 @@ int main (int argc, char **argv)
|
|||||||
OPENLOG ("useradd");
|
OPENLOG ("useradd");
|
||||||
|
|
||||||
sys_ngroups = sysconf (_SC_NGROUPS_MAX);
|
sys_ngroups = sysconf (_SC_NGROUPS_MAX);
|
||||||
user_groups = malloc ((1 + sys_ngroups) * sizeof (char *));
|
user_groups = xmalloc ((1 + sys_ngroups) * sizeof (char *));
|
||||||
/*
|
/*
|
||||||
* Initialize the list to be empty
|
* Initialize the list to be empty
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user