From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 7FBA71F4B4 for ; Wed, 20 Jan 2021 14:18:27 +0000 (UTC) Received: from localhost ([::1]:43562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l2EJW-0006QV-KB for normalperson@yhbt.net; Wed, 20 Jan 2021 09:18:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57194) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l25CU-0007yf-7Q for bug-gnulib@gnu.org; Tue, 19 Jan 2021 23:34:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45297) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l25CP-0002Z1-PA for bug-gnulib@gnu.org; Tue, 19 Jan 2021 23:34:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611117268; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=hxtkURZdmdntGDdQvJeZ0i0eLO9PR8Y86rKrMSVbQXk=; b=AC1MCFXWcTgtjZHSAzy3YnsS4iB5wyI8P4/1xwjBajnfgBVFhiITIueF4pMRgZZG3SzTwO LhGU3xphmw84nwxo51mbE10mk6SCvUoPZnLfMO1I3tMqrFo1O657oQLsCip9pedRn8XJNZ 2ooot9a/BpmRTmMrnd7j4qOd6KYt/So= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-568-4FZi6JyjOMiwXgeQFt1deQ-1; Tue, 19 Jan 2021 23:33:18 -0500 X-MC-Unique: 4FZi6JyjOMiwXgeQFt1deQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9D36815720; Wed, 20 Jan 2021 04:33:17 +0000 (UTC) Received: from greed.delorie.com (ovpn-113-151.rdu2.redhat.com [10.10.113.151]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6285D5D9DD; Wed, 20 Jan 2021 04:33:17 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.14.7/8.14.7) with ESMTP id 10K4XF79003838; Tue, 19 Jan 2021 23:33:16 -0500 From: DJ Delorie To: Adhemerval Zanella Subject: Re: [PATCH v3 6/6] stdlib: Add testcase fro BZ #26241 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) Date: Tue, 19 Jan 2021 23:33:15 -0500 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dj@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Received-SPF: pass client-ip=216.205.24.124; envelope-from=dj@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 20 Jan 2021 09:18:23 -0500 X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bug-gnulib@gnu.org, eggert@cs.ucla.edu, libc-alpha@sourceware.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" Adhemerval Zanella via Libc-alpha 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 > +#include > +#include > +#include Ok > +#define __sysconf sysconf > +#include > +#include > +#include > +#include > +#include > +#include 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 LGTM with that comment. Reviewed-by: DJ Delorie