aboutsummaryrefslogtreecommitdiff
path: root/stdlib/canonicalize.c
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@sourceware.org>2022-02-21 08:26:06 +0530
committerSiddhesh Poyarekar <siddhesh@sourceware.org>2022-02-21 08:26:33 +0530
commit949ad78a189194048df8a253bb31d1d11d919044 (patch)
treec4d2f8a544581a91225839aa8cfd67ddced94028 /stdlib/canonicalize.c
parentb98d0bbf747f39770e0caba7e984ce9f8f900330 (diff)
downloadglibc-949ad78a189194048df8a253bb31d1d11d919044.zip
glibc-949ad78a189194048df8a253bb31d1d11d919044.tar.gz
glibc-949ad78a189194048df8a253bb31d1d11d919044.tar.bz2
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 <siddhesh@sourceware.org> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'stdlib/canonicalize.c')
-rw-r--r--stdlib/canonicalize.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/stdlib/canonicalize.c b/stdlib/canonicalize.c
index 6caed9e..6237a41 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);