diff options
author | Michael Forney <mforney@mforney.org> | 2013-10-26 01:12:51 +0000 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2014-01-20 13:00:30 -0500 |
commit | c71d035097f67870496e0056370b57b379ef1798 (patch) | |
tree | e415efffa696efb3a4da36b9434f3fa16687d655 | |
parent | 2648470e54f614c867ded419f1fe9e3dc6fd3fd1 (diff) |
libudev-util.c: Handle -1 return from sysconf(_SC_GET{PW,GR}_R_SIZE_MAX)
POSIX says:
Note that sysconf(_SC_GETGR_R_SIZE_MAX) may return -1 if there is no
hard limit on the size of the buffer needed to store all the groups
returned.
The example from POSIX uses a default buffer size of 1024 in that case.
Signed-off-by: Michael Forney <mforney@mforney.org>
-rw-r--r-- | src/libudev/libudev-util.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c index 0f20e58586..2c31d5b1db 100644 --- a/src/libudev/libudev-util.c +++ b/src/libudev/libudev-util.c @@ -87,8 +87,11 @@ uid_t util_lookup_user(struct udev *udev, const char *user) struct passwd *pw; uid_t uid; size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX); - char *buf = alloca(buflen); + char *buf; + if (buflen == -1) + buflen = 1024; + buf = alloca(buflen); if (streq(user, "root")) return 0; uid = strtoul(user, &endptr, 10); @@ -114,6 +117,8 @@ gid_t util_lookup_group(struct udev *udev, const char *group) size_t buflen = sysconf(_SC_GETGR_R_SIZE_MAX); char *buf = NULL; + if (buflen == -1) + buflen = 1024; if (streq(group, "root")) return 0; gid = strtoul(group, &endptr, 10); |