summaryrefslogtreecommitdiff
path: root/libshouldbeinlibc/ugids-argp.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2008-04-24 00:11:41 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2008-04-24 00:11:41 +0000
commit30eeeae1a12c6cd015c174d9992aa3d0394036ef (patch)
tree0437346618acad1e29fbaf1ae61ace120f65e37a /libshouldbeinlibc/ugids-argp.c
parent0011847d5fa0e2dc5b53b50238d928547b57c248 (diff)
2008-03-19 Marc-Olivier Mercier <mercier.m@sympatico.ca>
* ugids-argp.c (parse_opt): Check NULL condition for struct passwd (resp. group) pointer returned by getpwnam_r (resp. getgrnam_r).
Diffstat (limited to 'libshouldbeinlibc/ugids-argp.c')
-rw-r--r--libshouldbeinlibc/ugids-argp.c43
1 files changed, 32 insertions, 11 deletions
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: