]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
realpath: Do not copy result on failure (BZ #28815)
authorSiddhesh Poyarekar <siddhesh@sourceware.org>
Mon, 21 Feb 2022 02:56:06 +0000 (08:26 +0530)
committerSiddhesh Poyarekar <siddhesh@sourceware.org>
Mon, 21 Feb 2022 02:56:33 +0000 (08:26 +0530)
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>
stdlib/canonicalize.c
stdlib/test-canon.c

index 6caed9e70e14827f4320a6894a132ad4095a1065..6237a41d42bbf9596570e7d625bbbb620ada6e1c 100644 (file)
@@ -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);
index 185ccf4f483108caf16ad45ee0303539b525dff9..2ad1218749dc79e25f0b4d1947c6bfbef436eb82 100644 (file)
@@ -174,7 +174,9 @@ do_test (int argc, char ** argv)
          continue;
        }
 
-      if (!check_path (buf, tests[i].out ? tests[i].out : tests[i].resolved))
+      /* Only on success verify that buf contains the result too.  */
+      if (result != NULL
+         && !check_path (buf, tests[i].out ? tests[i].out : tests[i].resolved))
        {
          printf ("%s: flunked test %d (expected resolved `%s', got `%s')\n",
                  argv[0], i, tests[i].out ? tests[i].out : tests[i].resolved,