aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2018-10-30 16:02:39 +0100
committerJakub Jelen <jjelen@redhat.com>2018-10-30 16:22:17 +0100
commitd85bc347d3274e4457c4c2d19d4f12c8a6434e46 (patch)
tree805b31e8096b1a73282ec6ca247f9394a6018bd1
parent9c4baa7fd58b9e4d9cdab4a03d18dd03e0e587ab (diff)
downloadlibssh-d85bc347d3274e4457c4c2d19d4f12c8a6434e46.tar.gz
libssh-d85bc347d3274e4457c4c2d19d4f12c8a6434e46.tar.xz
libssh-d85bc347d3274e4457c4c2d19d4f12c8a6434e46.zip
misc: Properly check for errors returned from getpwuid_r()
Resolves: T118 Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--src/misc.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/misc.c b/src/misc.c
index 90b63330..782b7bc0 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -217,12 +217,12 @@ char *ssh_get_user_home_dir(void)
{
char *szPath = NULL;
struct passwd pwd;
- struct passwd *pwdbuf;
+ struct passwd *pwdbuf = NULL;
char buf[NSS_BUFLEN_PASSWD] = {0};
int rc;
rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
- if (rc != 0) {
+ if (rc != 0 || pwdbuf == NULL ) {
szPath = getenv("HOME");
if (szPath == NULL) {
return NULL;
@@ -250,13 +250,13 @@ int ssh_file_readaccess_ok(const char *file)
char *ssh_get_local_username(void)
{
struct passwd pwd;
- struct passwd *pwdbuf;
+ struct passwd *pwdbuf = NULL;
char buf[NSS_BUFLEN_PASSWD];
char *name;
int rc;
rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
- if (rc != 0) {
+ if (rc != 0 || pwdbuf == NULL) {
return NULL;
}