aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2012-10-08 22:38:20 +0200
committerAndreas Schneider <asn@cryptomilk.org>2012-10-12 14:45:54 +0200
commite04dc45f2043e8bf0a837eda84a909fa45cadf87 (patch)
treee0d2e49e9e3a7ea65342db2fb67c689b1679c37e /src
parentde34a6489543e387bff8ef4fd615cbf069c57e93 (diff)
downloadlibssh-e04dc45f2043e8bf0a837eda84a909fa45cadf87.tar.gz
libssh-e04dc45f2043e8bf0a837eda84a909fa45cadf87.tar.xz
libssh-e04dc45f2043e8bf0a837eda84a909fa45cadf87.zip
misc: Use a fixed buffer for getenv().
Diffstat (limited to 'src')
-rw-r--r--src/misc.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/misc.c b/src/misc.c
index 14ca6162..64d9e0c2 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -214,8 +214,14 @@ char *ssh_get_user_home_dir(void) {
rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
if (rc != 0) {
- szPath=getenv("HOME");
- return szPath ? strdup(szPath) : NULL;
+ szPath = getenv("HOME");
+ if (szPath == NULL) {
+ return NULL;
+ }
+ memset(buf, 0, sizeof(buf));
+ snprintf(buf, sizeof(buf), "%s", getenv("HOME"));
+
+ return strdup(buf);
}
szPath = strdup(pwd.pw_dir);