From 30eeeae1a12c6cd015c174d9992aa3d0394036ef Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Thu, 24 Apr 2008 00:11:41 +0000 Subject: 2008-03-19 Marc-Olivier Mercier * ugids-argp.c (parse_opt): Check NULL condition for struct passwd (resp. group) pointer returned by getpwnam_r (resp. getgrnam_r). --- libshouldbeinlibc/ChangeLog | 5 +++++ libshouldbeinlibc/ugids-argp.c | 43 +++++++++++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/libshouldbeinlibc/ChangeLog b/libshouldbeinlibc/ChangeLog index 26d2424e..968f836d 100644 --- a/libshouldbeinlibc/ChangeLog +++ b/libshouldbeinlibc/ChangeLog @@ -1,3 +1,8 @@ +2008-03-19 Marc-Olivier Mercier + + * ugids-argp.c (parse_opt): Check NULL condition for struct passwd + (resp. group) pointer returned by getpwnam_r (resp. getgrnam_r). + 2008-03-16 Samuel Thibault * idvec-verify.c (verify_id): Compare id to (uid_t) -1 instead of diff --git a/libshouldbeinlibc/ugids-argp.c b/libshouldbeinlibc/ugids-argp.c index 809da784..bd2dc4f1 100644 --- a/libshouldbeinlibc/ugids-argp.c +++ b/libshouldbeinlibc/ugids-argp.c @@ -83,13 +83,24 @@ parse_opt (int key, char *arg, struct argp_state *state) else { struct passwd _pw, *pw; - if (getpwnam_r (arg, &_pw, id_lookup_buf, sizeof id_lookup_buf, &pw) - == 0) - uid = pw->pw_uid; + int err; + err = getpwnam_r (arg, &_pw, id_lookup_buf, + sizeof id_lookup_buf, &pw); + if (err == 0) + { + if (pw == NULL) + { + argp_failure (state, 10, 0, "%s: Unknown user", arg); + return EINVAL; + } + + uid = pw->pw_uid; + } else { - argp_failure (state, 10, 0, "%s: Unknown user", arg); - return EINVAL; + argp_failure (state, 12, err, + "Could not get uid for user: %s", arg); + return err; } } @@ -121,14 +132,24 @@ parse_opt (int key, char *arg, struct argp_state *state) else { struct group _gr, *gr; - if (getgrnam_r (arg, &_gr, id_lookup_buf, sizeof id_lookup_buf, &gr) - == 0) - return ugids_add_gid (ugids, gr->gr_gid, key == 'G'); - else + int err = getgrnam_r (arg, &_gr, id_lookup_buf, + sizeof id_lookup_buf, &gr); + if (err == 0) { - argp_failure (state, 11, 0, "%s: Unknown group", arg); - return EINVAL; + if (gr == NULL) + { + argp_failure (state, 11, 0, "%s: Unknown group", arg); + return EINVAL; + } + + return ugids_add_gid (ugids, gr->gr_gid, key == 'G'); } + else + { + argp_failure (state, 13, err, + "Could not get gid for group: %s", arg); + return err; + } } default: -- cgit v1.2.3