s3: VFS: Protect errno if sys_getwd() fails across free() call.
authorJeremy Allison <jra@samba.org>
Tue, 3 Oct 2017 17:58:00 +0000 (10:58 -0700)
committerKarolin Seeger <kseeger@samba.org>
Wed, 25 Oct 2017 06:43:04 +0000 (08:43 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13069

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
(cherry picked from commit 4800ed3595513ce1e2f4edee36c35daafc63a3d5)

source3/lib/system.c

index 01c934277acb6f31653eab9d39aea2eb028cf999..014731901476e53b4a8473905f5c33717eef3298 100644 (file)
@@ -594,7 +594,9 @@ char *sys_getwd(void)
                        break;
                }
                if (errno != ERANGE) {
+                       int saved_errno = errno;
                        SAFE_FREE(s);
+                       errno = saved_errno;
                        break;
                }
                allocated *= 2;
@@ -612,7 +614,9 @@ char *sys_getwd(void)
        }
        wd = getwd(s);
        if (wd == NULL) {
+               int saved_errno = errno;
                SAFE_FREE(s);
+               errno = saved_errno;
        }
        return wd;
 #endif