From 949ad78a189194048df8a253bb31d1d11d919044 Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Mon, 21 Feb 2022 08:26:06 +0530 Subject: realpath: Do not copy result on failure (BZ #28815) On failure, the contents of the resolved buffer passed in by the caller to realpath are undefined. Do not copy any partial resolution to the buffer and also do not test resolved contents in test-canon.c. Resolves: BZ #28815 Signed-off-by: Siddhesh Poyarekar Reviewed-by: Adhemerval Zanella --- stdlib/canonicalize.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'stdlib/canonicalize.c') diff --git a/stdlib/canonicalize.c b/stdlib/canonicalize.c index 6caed9e70e..6237a41d42 100644 --- a/stdlib/canonicalize.c +++ b/stdlib/canonicalize.c @@ -400,11 +400,11 @@ realpath_stk (const char *name, char *resolved, error: *dest++ = '\0'; - if (resolved != NULL) + if (!failed && resolved != NULL) { if (dest - rname <= get_path_max ()) rname = strcpy (resolved, rname); - else if (!failed) + else { failed = true; __set_errno (ENAMETOOLONG); -- cgit 1.4.1