From 4800ed3595513ce1e2f4edee36c35daafc63a3d5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 3 Oct 2017 10:58:00 -0700 Subject: [PATCH] s3: VFS: Protect errno if sys_getwd() fails across free() call. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13069 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme --- source3/lib/system.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source3/lib/system.c b/source3/lib/system.c index 5baa8f7d3ff..507d4a9af93 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -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