public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] realpath: Do not copy result on failure (BZ #28815)
@ 2022-01-24 16:54 Siddhesh Poyarekar
  2022-02-10 12:36 ` Adhemerval Zanella
  0 siblings, 1 reply; 2+ messages in thread
From: Siddhesh Poyarekar @ 2022-01-24 16:54 UTC (permalink / raw)
  To: libc-alpha

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>
---
 stdlib/canonicalize.c | 4 ++--
 stdlib/test-canon.c   | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)

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);
diff --git a/stdlib/test-canon.c b/stdlib/test-canon.c
index 185ccf4f48..2ad1218749 100644
--- a/stdlib/test-canon.c
+++ b/stdlib/test-canon.c
@@ -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,
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] realpath: Do not copy result on failure (BZ #28815)
  2022-01-24 16:54 [PATCH] realpath: Do not copy result on failure (BZ #28815) Siddhesh Poyarekar
@ 2022-02-10 12:36 ` Adhemerval Zanella
  0 siblings, 0 replies; 2+ messages in thread
From: Adhemerval Zanella @ 2022-02-10 12:36 UTC (permalink / raw)
  To: Siddhesh Poyarekar, libc-alpha



On 24/01/2022 13:54, Siddhesh Poyarekar via Libc-alpha wrote:
> 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>

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  stdlib/canonicalize.c | 4 ++--
>  stdlib/test-canon.c   | 4 +++-
>  2 files changed, 5 insertions(+), 3 deletions(-)
> 
> 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);
> diff --git a/stdlib/test-canon.c b/stdlib/test-canon.c
> index 185ccf4f48..2ad1218749 100644
> --- a/stdlib/test-canon.c
> +++ b/stdlib/test-canon.c
> @@ -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,

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-10 12:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 16:54 [PATCH] realpath: Do not copy result on failure (BZ #28815) Siddhesh Poyarekar
2022-02-10 12:36 ` Adhemerval Zanella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).