bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: DJ Delorie <dj@redhat.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: bug-gnulib@gnu.org, eggert@cs.ucla.edu, libc-alpha@sourceware.org
Subject: Re: [PATCH v3 6/6] stdlib: Add testcase fro BZ #26241
Date: Tue, 19 Jan 2021 23:33:15 -0500	[thread overview]
Message-ID: <xnpn20ut10.fsf@greed.delorie.com> (raw)
In-Reply-To: <20201229193454.34558-7-adhemerval.zanella@linaro.org> (message from Adhemerval Zanella via Libc-alpha on Tue, 29 Dec 2020 16:34:54 -0300)


Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org> writes:
> -		   tst-setcontext9 tst-bz20544
> +		   tst-setcontext9 tst-bz20544 tst-canon-bz26341

New test, ok.

> +LDLIBS-tst-canon-bz26341 = $(shared-thread-library)

Ok.

> diff --git a/stdlib/tst-canon-bz26341.c b/stdlib/tst-canon-bz26341.c

> +/* Check if realpath does not consume extra stack space based on symlink
> +   existance in the path (BZ #26341)

Is this allowed to be two lines?

> +   Copyright (C) 2020 Free Software Foundation, Inc.

Year is wrong now :-)

> +#include <stdlib.h>
> +#include <string.h>
> +#include <sys/param.h>
> +#include <unistd.h>

Ok

> +#define __sysconf sysconf
> +#include <eloop-threshold.h>
> +#include <support/check.h>
> +#include <support/support.h>
> +#include <support/temp_file.h>
> +#include <support/xunistd.h>
> +#include <support/xthread.h>

Ok

> +static char *filename;
> +static size_t filenamelen;
> +static char *linkname;
> +
> +#ifndef PATH_MAX
> +# define PATH_MAX 1024
> +#endif

Ok.

> +static void
> +create_link (void)
> +{
> +  int fd = create_temp_file ("tst-canon-bz26341", &filename);
> +  TEST_VERIFY_EXIT (fd != -1);
> +  xclose (fd);
> +
> +  char *prevlink = filename;
> +  int maxlinks = __eloop_threshold ();
> +  for (int i = 0; i < maxlinks; i++)
> +    {
> +      linkname = xasprintf ("%s%d", filename, i);
> +      xsymlink (prevlink, linkname);

linkname -> prevlink -> filename

> +      add_temp_file (linkname);
> +      prevlink = linkname;
> +    }
> +
> +  filenamelen = strlen (filename);
> +}

On exit, linkname has the last link created.  Needs a comment to that
effect.


> +static void *
> +do_realpath (void *arg)
> +{
> +  /* Old implementation of realpath allocates a PATH_MAX using alloca
> +     for each symlink in the path, leading to MAXSYMLINKS times PATH_MAX
> +     maximum stack usage.
> +     This stack allocations tries fill the thread allocated stack minus
> +     both the resolved path (plus some slack) and the realpath (plus some
> +     slack).
> +     If realpath uses more than 2 * PATH_MAX plus some slack it will trigger
> +     a stackoverflow.  */
> +
> +  const size_t realpath_usage = 2 * PATH_MAX + 1024;
> +  const size_t thread_usage = 1 * PATH_MAX + 1024;
> +  size_t stack_size = support_small_thread_stack_size ()
> +		      - realpath_usage - thread_usage;
> +  char stack[stack_size];
> +  char *resolved = stack + stack_size - thread_usage + 1024;

This points us at PATH_MAX away from the end of stack[].  Ok.  Also
forces most of the stack to get used up :-)

> +  char *p = realpath (linkname, resolved);

We assume the test will crash if we use more stack than we allocated.

> +  TEST_VERIFY (p != NULL);

realpath() must succeed, ok

> +  TEST_COMPARE_BLOB (resolved, filenamelen, filename, filenamelen);

And give us the right result, ok

> +  return NULL;
> +}
> +
> +static int
> +do_test (void)
> +{
> +  create_link ();
> +
> +  pthread_t th = xpthread_create (support_small_stack_thread_attribute (),
> +				  do_realpath, NULL);
> +  xpthread_join (th);
> +
> +  return 0;
> +}

Run the test in a thread with a small stack, ok.

> +#include <support/test-driver.c>

LGTM with that comment.

Reviewed-by: DJ Delorie <dj@redhat.com>



  reply	other threads:[~2021-01-20 14:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-29 19:34 [PATCH v3 0/6] Multiple fixes to realpath Adhemerval Zanella
2020-12-29 19:34 ` [PATCH v3 1/6] Import idx.h from gnulib Adhemerval Zanella
2020-12-29 19:34 ` [PATCH v3 2/6] Import filename.h " Adhemerval Zanella
2020-12-29 19:34 ` [PATCH v3 3/6] malloc: Add scratch_buffer_dupfree Adhemerval Zanella
2020-12-29 19:34 ` [PATCH v3 4/6] stdlib: Sync canonicalize with gnulib [BZ #10635] [BZ #26592] [BZ #26341] [BZ #24970] Adhemerval Zanella
2020-12-30  1:21   ` Paul Eggert
2020-12-30  3:39     ` Paul Eggert
2020-12-30  6:19       ` Paul Eggert
2020-12-30 12:34     ` Adhemerval Zanella
2020-12-30 13:10       ` Adhemerval Zanella
2021-01-02  0:04         ` Paul Eggert
2021-01-04 12:52           ` Adhemerval Zanella
2021-01-09  1:24             ` Paul Eggert
2020-12-29 19:34 ` [PATCH v3 5/6] support: Add support_small_thread_stack_size Adhemerval Zanella
2020-12-30  8:54   ` Florian Weimer
2020-12-29 19:34 ` [PATCH v3 6/6] stdlib: Add testcase fro BZ #26241 Adhemerval Zanella
2021-01-20  4:33   ` DJ Delorie [this message]
2021-01-20 14:13     ` Adhemerval Zanella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xnpn20ut10.fsf@greed.delorie.com \
    --to=dj@redhat.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=bug-gnulib@gnu.org \
    --cc=eggert@cs.ucla.edu \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).