diff options
author | Eric Koegel <eric.koegel@gmail.com> | 2014-10-10 20:04:16 +0300 |
---|---|---|
committer | Eric Koegel <eric.koegel@gmail.com> | 2014-10-10 20:05:23 +0300 |
commit | a36040d6cec71e5dbe39b8f20c2da6facbf89397 (patch) | |
tree | a4e062e3dbf4c58812c137e0be0786d1013bac54 | |
parent | 77349219b052969bee29be7702035256d1bc04cf (diff) | |
download | ConsoleKit2-a36040d6cec71e5dbe39b8f20c2da6facbf89397.tar.gz |
Argument cannot be negative
1) sysconf returns a long so make bufsize one.
2) sysconf call can fail and return -1, handle that condition.
3) if sysconf does fail a negative value would be sent to calloc
which expects a positive value.
-rw-r--r-- | pam-ck-connector/pam-ck-connector.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/pam-ck-connector/pam-ck-connector.c b/pam-ck-connector/pam-ck-connector.c index 949a9b0..65c08d6 100644 --- a/pam-ck-connector/pam-ck-connector.c +++ b/pam-ck-connector/pam-ck-connector.c @@ -189,13 +189,16 @@ _util_name_to_uid (const char *username, int rc; uid_t res; char *buf = NULL; - unsigned int bufsize; + long bufsize; struct passwd pwd; struct passwd *pwdp; res = (uid_t) -1; bufsize = sysconf (_SC_GETPW_R_SIZE_MAX); + if (bufsize == -1) { + return res; + } buf = calloc (sizeof (char), bufsize); rc = getpwnam_r (username, &pwd, buf, bufsize, &pwdp); if (rc != 0 || pwdp == NULL) { |