From patchwork Mon Dec 28 13:59:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1420876 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=xuQP/q5K; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D4K1X6Rx0zB3tV for ; Tue, 29 Dec 2020 01:00:00 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7BBDB38708FB; Mon, 28 Dec 2020 13:59:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7BBDB38708FB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1609163993; bh=i7NvhQAm6Ui57UistCytNO9Wa9rzZEg6bbu2hOKCEBc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=xuQP/q5KtjDBjjQ4HyovSohVBUvJiOOtKlfbJlKYbdtStTRKtnwNNSHPbCeMgDBD+ tjrfE82JvYNf2kjcV7eKeKwN/ShWZAKX7hCllt0mslweSfqa3qvETyZpUPr9v4Inl2 xgmnbtcPkPBCko4vKA9ja6po2eto6WM2Cv44OK24= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by sourceware.org (Postfix) with ESMTPS id 4734638708CC for ; Mon, 28 Dec 2020 13:59:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4734638708CC Received: by mail-qt1-x82f.google.com with SMTP id c14so6926803qtn.0 for ; Mon, 28 Dec 2020 05:59:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=i7NvhQAm6Ui57UistCytNO9Wa9rzZEg6bbu2hOKCEBc=; b=mqlXH7J4eWafRakoQcPXTNJPzbAnXBUaJH6GA3r/vwuWmz6zrd3w15FcDEDO4o+h9+ ZtApxIeulg3H7jeGyK4YUvTYi8iTeo6c8K16KMz4Q0XwjT6mZhWD3dR0e2x99yhDoo5V 1umaJHLHwkBG/jG6FqfpiuwZ+OfacRDsgwtdcAaSLKbGf6n0G/wkXmrG4nMyIBIp0VRu kUaT2VFf+3nA/18T2UZGSWd9eQpoP208dFtNUApoNcaqKKoZuQ0a9MC5/NsJ9aoUuIn7 0mC6uQQ6TmG349kHAWWaimf+UIKPtgFkHB54D4rZXopoXbUuVar4HXAtc8xp5pY8l+f3 J+KQ== X-Gm-Message-State: AOAM533gYF1cjV8WVQHJyYQURi5T0taX4LPa/Dr+SiDWAlhf1PlUtMeC 7GyokITK5iCNBzughIoZBfSLFHi+7ekDug== X-Google-Smtp-Source: ABdhPJz/iYhMoOjBzi38aiqhgHidOWroO1sLIYroxE0/POaDGgAmunQ6K6N44++DK9ssJjZqe+Hu4g== X-Received: by 2002:ac8:5359:: with SMTP id d25mr45412577qto.132.1609163989598; Mon, 28 Dec 2020 05:59:49 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id i17sm24243744qtg.77.2020.12.28.05.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 05:59:49 -0800 (PST) To: libc-alpha@sourceware.org, Paul Eggert Subject: [PATCH v2 1/6] Import idx.h from gnulib Date: Mon, 28 Dec 2020 10:59:39 -0300 Message-Id: <20201228135944.1018303-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: bug-gnulib@gnu.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Changes from previous version: - Change idx.h comment to LGPLv2.1+. --- And use to simplify stdlib/canonicalize.c implementation. --- include/idx.h | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 include/idx.h diff --git a/include/idx.h b/include/idx.h new file mode 100644 index 0000000000..024b44ae98 --- /dev/null +++ b/include/idx.h @@ -0,0 +1,114 @@ +/* A type for indices and sizes. + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _IDX_H +#define _IDX_H + +/* Get ptrdiff_t. */ +#include + +/* Get PTRDIFF_MAX. */ +#include + +/* The type 'idx_t' holds an (array) index or an (object) size. + Its implementation promotes to a signed integer type, + which can hold the values + 0..2^63-1 (on 64-bit platforms) or + 0..2^31-1 (on 32-bit platforms). + + Why a signed integer type? + + * Security: Signed types can be checked for overflow via + '-fsanitize=undefined', but unsigned types cannot. + + * Comparisons without surprises: ISO C99 § 6.3.1.8 specifies a few + surprising results for comparisons, such as + + (int) -3 < (unsigned long) 7 => false + (int) -3 < (unsigned int) 7 => false + and on 32-bit machines: + (long) -3 < (unsigned int) 7 => false + + This is surprising because the natural comparison order is by + value in the realm of infinite-precision signed integers (ℤ). + + The best way to get rid of such surprises is to use signed types + for numerical integer values, and use unsigned types only for + bit masks and enums. + + Why not use 'size_t' directly? + + * Because 'size_t' is an unsigned type, and a signed type is better. + See above. + + Why not use 'ptrdiff_t' directly? + + * Maintainability: When reading and modifying code, it helps to know that + a certain variable cannot have negative values. For example, when you + have a loop + + int n = ...; + for (int i = 0; i < n; i++) ... + + or + + ptrdiff_t n = ...; + for (ptrdiff_t i = 0; i < n; i++) ... + + you have to ask yourself "what if n < 0?". Whereas in + + idx_t n = ...; + for (idx_t i = 0; i < n; i++) ... + + you know that this case cannot happen. + + Similarly, when a programmer writes + + idx_t = ptr2 - ptr1; + + there is an implied assertion that ptr1 and ptr2 point into the same + object and that ptr1 <= ptr2. + + * Being future-proof: In the future, range types (integers which are + constrained to a certain range of values) may be added to C compilers + or to the C standard. Several programming languages (Ada, Haskell, + Common Lisp, Pascal) already have range types. Such range types may + help producing good code and good warnings. The type 'idx_t' could + then be typedef'ed to a range type that is signed after promotion. */ + +/* In the future, idx_t could be typedef'ed to a signed range type. + The clang "extended integer types", supported in Clang 11 or newer + , + are a special case of range types. However, these types don't support binary + operators with plain integer types (e.g. expressions such as x > 1). + Therefore, they don't behave like signed types (and not like unsigned types + either). So, we cannot use them here. */ + +/* Use the signed type 'ptrdiff_t'. */ +/* Note: ISO C does not mandate that 'size_t' and 'ptrdiff_t' have the same + size, but it is so on all platforms we have seen since 1990. */ +typedef ptrdiff_t idx_t; + +/* IDX_MAX is the maximum value of an idx_t. */ +#define IDX_MAX PTRDIFF_MAX + +/* So far no need has been found for an IDX_WIDTH macro. + Perhaps there should be another macro IDX_VALUE_BITS that does not + count the sign bit and is therefore one less than PTRDIFF_WIDTH. */ + +#endif /* _IDX_H */ From patchwork Mon Dec 28 13:59:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1420877 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=RonoRoEU; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D4K1b5VNlz9sTm for ; Tue, 29 Dec 2020 01:00:03 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C7D13870907; Mon, 28 Dec 2020 13:59:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C7D13870907 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1609163995; bh=UVf+JPK8wCFw72LCV+7v7ioEUFedK6SGQCrfpwt75KI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=RonoRoEUzD2J11jt4g1HZaOAJiqJeALNFDlmtguJ5Kl4YBAhgS9wbGoqkvQrieKhx sF6KoRyELcASmYjwka6ATZzQz0T1vVrH6DvLvnoQpQMZ6rI5A7VxH50pcMKdoc2Qaw GSNgznFC7UTmCoy/IAJeuCtgw8UtVXRmz5r1Vc6U= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by sourceware.org (Postfix) with ESMTPS id 039D238708CC for ; Mon, 28 Dec 2020 13:59:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 039D238708CC Received: by mail-qk1-x733.google.com with SMTP id f26so8861460qka.0 for ; Mon, 28 Dec 2020 05:59:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UVf+JPK8wCFw72LCV+7v7ioEUFedK6SGQCrfpwt75KI=; b=I8GZPn962PEYieh5DcQBCMD/iJHPnZT7cEhk1pJXEYaRhmxgNn4y3v/+c4YUl1E+dV 1VPuYatPHdf1PywZh1GxOHpZS52z8nZuCJtZKOIQDQM9k6FkdOa3akbUb9AtBgpoVcYn YYKXNHvr4W1ledAM8xQ0J6tKfBrJXI6GvxOWdLFqkqrub1DpLxvHbklfgykL8JZXcY5g tXKKNzwg83xM16aZ3ocOsw4Y+ZgIoPIZDwOudDBkVkR+M+hzIyvGJDY4or1av7V+kqoS k+ZbhApgZzKmV3OL75ObMGLGqKh1QSeuFofok8UDIshW796r6pPbKSD60ShJv9TrZScJ 8p1Q== X-Gm-Message-State: AOAM532plT+EZMiq1+XrvXgYHI9u5Vmx4rXBNhkwFthZ9T5xSx75R4GU 4N5R1XhfO/yIfrsKABogzBDIUOM/q2JwHA== X-Google-Smtp-Source: ABdhPJy+U4/ZbjApUPu2eIQjGOKF0In//EIyee36wPtWtvc8coKGKnozHtkkHKh9lm5DgDy/3mJmjw== X-Received: by 2002:ae9:e010:: with SMTP id m16mr24405648qkk.442.1609163991310; Mon, 28 Dec 2020 05:59:51 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id i17sm24243744qtg.77.2020.12.28.05.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 05:59:50 -0800 (PST) To: libc-alpha@sourceware.org, Paul Eggert Subject: [PATCH v2 2/6] Import filename.h from gnulib Date: Mon, 28 Dec 2020 10:59:40 -0300 Message-Id: <20201228135944.1018303-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201228135944.1018303-1-adhemerval.zanella@linaro.org> References: <20201228135944.1018303-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: bug-gnulib@gnu.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" And use to simplify stdlib/canonicalize.c implementation. --- include/filename.h | 110 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 include/filename.h diff --git a/include/filename.h b/include/filename.h new file mode 100644 index 0000000000..4598fb1d63 --- /dev/null +++ b/include/filename.h @@ -0,0 +1,110 @@ +/* Basic filename support macros. + Copyright (C) 2001-2004, 2007-2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* From Paul Eggert and Jim Meyering. */ + +#ifndef _FILENAME_H +#define _FILENAME_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Filename support. + ISSLASH(C) tests whether C is a directory separator + character. + HAS_DEVICE(Filename) tests whether Filename contains a device + specification. + FILE_SYSTEM_PREFIX_LEN(Filename) length of the device specification + at the beginning of Filename, + index of the part consisting of + alternating components and slashes. + FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE + 1 when a non-empty device specification + can be followed by an empty or relative + part, + 0 when a non-empty device specification + must be followed by a slash, + 0 when device specification don't exist. + IS_ABSOLUTE_FILE_NAME(Filename) + tests whether Filename is independent of + any notion of "current directory". + IS_RELATIVE_FILE_NAME(Filename) + tests whether Filename may be concatenated + to a directory filename. + Note: On native Windows, OS/2, DOS, "c:" is neither an absolute nor a + relative file name! + IS_FILE_NAME_WITH_DIR(Filename) tests whether Filename contains a device + or directory specification. + */ +#if defined _WIN32 || defined __CYGWIN__ \ + || defined __EMX__ || defined __MSDOS__ || defined __DJGPP__ + /* Native Windows, Cygwin, OS/2, DOS */ +# define ISSLASH(C) ((C) == '/' || (C) == '\\') + /* Internal macro: Tests whether a character is a drive letter. */ +# define _IS_DRIVE_LETTER(C) \ + (((C) >= 'A' && (C) <= 'Z') || ((C) >= 'a' && (C) <= 'z')) + /* Help the compiler optimizing it. This assumes ASCII. */ +# undef _IS_DRIVE_LETTER +# define _IS_DRIVE_LETTER(C) \ + (((unsigned int) (C) | ('a' - 'A')) - 'a' <= 'z' - 'a') +# define HAS_DEVICE(Filename) \ + (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':') +# define FILE_SYSTEM_PREFIX_LEN(Filename) (HAS_DEVICE (Filename) ? 2 : 0) +# ifdef __CYGWIN__ +# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0 +# else + /* On native Windows, OS/2, DOS, the system has the notion of a + "current directory" on each drive. */ +# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1 +# endif +# if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE +# define IS_ABSOLUTE_FILE_NAME(Filename) \ + ISSLASH ((Filename)[FILE_SYSTEM_PREFIX_LEN (Filename)]) +# else +# define IS_ABSOLUTE_FILE_NAME(Filename) \ + (ISSLASH ((Filename)[0]) || HAS_DEVICE (Filename)) +# endif +# define IS_RELATIVE_FILE_NAME(Filename) \ + (! (ISSLASH ((Filename)[0]) || HAS_DEVICE (Filename))) +# define IS_FILE_NAME_WITH_DIR(Filename) \ + (strchr ((Filename), '/') != NULL || strchr ((Filename), '\\') != NULL \ + || HAS_DEVICE (Filename)) +#else + /* Unix */ +# define ISSLASH(C) ((C) == '/') +# define HAS_DEVICE(Filename) ((void) (Filename), 0) +# define FILE_SYSTEM_PREFIX_LEN(Filename) ((void) (Filename), 0) +# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0 +# define IS_ABSOLUTE_FILE_NAME(Filename) ISSLASH ((Filename)[0]) +# define IS_RELATIVE_FILE_NAME(Filename) (! ISSLASH ((Filename)[0])) +# define IS_FILE_NAME_WITH_DIR(Filename) (strchr ((Filename), '/') != NULL) +#endif + +/* Deprecated macros. For backward compatibility with old users of the + 'filename' module. */ +#define IS_ABSOLUTE_PATH IS_ABSOLUTE_FILE_NAME +#define IS_PATH_WITH_DIR IS_FILE_NAME_WITH_DIR + + +#ifdef __cplusplus +} +#endif + +#endif /* _FILENAME_H */ From patchwork Mon Dec 28 13:59:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1420878 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=URKh6Ldb; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D4K1h1qmGzB3vN for ; Tue, 29 Dec 2020 01:00:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A4A23840C16; Mon, 28 Dec 2020 13:59:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A4A23840C16 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1609163997; bh=u8hGdF6dpmXVclcmm3bEdMe3tgFRvcQtcTiW2ZTROXw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=URKh6Ldbq+eo0eA3fp1JUJVhZhWd/O5Tq7swHf+Dhy+mukY6Zevmot6uOctm5cYpD b/6S2Yzurexs5iwQSCxMLk5GX7KalxsrGpZq/p2tmdnAOZDUp4Qy6hRFIXLQ0BI/n2 B4hzLnEUW20sLlidniaroEpvhruSbyEvy7B59aLw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by sourceware.org (Postfix) with ESMTPS id C2F4738708FF for ; Mon, 28 Dec 2020 13:59:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C2F4738708FF Received: by mail-qv1-xf2f.google.com with SMTP id h16so4943569qvu.8 for ; Mon, 28 Dec 2020 05:59:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u8hGdF6dpmXVclcmm3bEdMe3tgFRvcQtcTiW2ZTROXw=; b=U2xPrD2hZQLGDV41+PqQuEIkDKW6G3sxxngGZXOgiphntkFTP/ibJrPkNL3dv37WQm yIUwVJ0EKDlJSUgga5ySMlNlcVgLuw7Jcae0iPZjoQXSBFkhnKDARusRiEikq1yot9wE JGXb0eFt5iiZWjntzXZMlM7qpE+13bvRWSS4AUJSB71VGsHYqMS8LFqt0rbbUW+uUNVq VyCK2JqkrHKmwjwdlfDI8DaxpcQnFnowHklzV0rsddXLSP5rsxJH6nbySifQsBKx0fm9 oVQN/xRicsGabrFNwFRcXn8MH7gk8CNLw6kD8MGnhWFm1Y55qvIB3iFiwiQQhqQKPo/e iktg== X-Gm-Message-State: AOAM531oqMY+AoRQU0jOvDCgwdAT+OzaEvFrmwbwR4vh833HzkI+SOU2 G+Q06xtRwVK9monFde0I75bUrtBnfB1AdA== X-Google-Smtp-Source: ABdhPJz2+i0Z6+VBv0pv+F7fwJvQB18eU/UdsTNbWiS1jV3q6lfGRBr0pc1a38IsEIqtt5YQHD33Iw== X-Received: by 2002:a05:6214:a14:: with SMTP id dw20mr46558075qvb.43.1609163993063; Mon, 28 Dec 2020 05:59:53 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id i17sm24243744qtg.77.2020.12.28.05.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 05:59:52 -0800 (PST) To: libc-alpha@sourceware.org, Paul Eggert Subject: [PATCH v2 3/6] malloc: Add scratch_buffer_dupfree Date: Mon, 28 Dec 2020 10:59:41 -0300 Message-Id: <20201228135944.1018303-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201228135944.1018303-1-adhemerval.zanella@linaro.org> References: <20201228135944.1018303-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: bug-gnulib@gnu.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" It returns a copy of the buffer up to a defined size. It will be used on realpath sync with gnulib. --- include/scratch_buffer.h | 16 +++++++++++++ malloc/Makefile | 1 + malloc/Versions | 1 + malloc/scratch_buffer_dupfree.c | 41 +++++++++++++++++++++++++++++++++ malloc/tst-scratch_buffer.c | 26 +++++++++++++++++++-- 5 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 malloc/scratch_buffer_dupfree.c diff --git a/include/scratch_buffer.h b/include/scratch_buffer.h index c39da78629..48d651b41a 100644 --- a/include/scratch_buffer.h +++ b/include/scratch_buffer.h @@ -132,4 +132,20 @@ scratch_buffer_set_array_size (struct scratch_buffer *buffer, (buffer, nelem, size)); } +/* Return a copy of *BUFFER's first SIZE bytes as a heap-allocated block, + deallocating *BUFFER if it was heap-allocated. SIZE must be at + most *BUFFER's size. Return NULL (setting errno) on memory + exhaustion. */ +void *__libc_scratch_buffer_dupfree (struct scratch_buffer *buffer, + size_t size); +libc_hidden_proto (__libc_scratch_buffer_dupfree) + +/* Alias for __libc_scratch_dupfree. */ +static __always_inline void * +scratch_buffer_dupfree (struct scratch_buffer *buffer, size_t size) +{ + void *r = __libc_scratch_buffer_dupfree (buffer, size); + return __glibc_likely (r != NULL) ? r : NULL; +} + #endif /* _SCRATCH_BUFFER_H */ diff --git a/malloc/Makefile b/malloc/Makefile index ab64dcfd73..f0ec3dae6b 100644 --- a/malloc/Makefile +++ b/malloc/Makefile @@ -63,6 +63,7 @@ tests += $(tests-static) test-srcs = tst-mtrace routines = malloc morecore mcheck mtrace obstack reallocarray \ + scratch_buffer_dupfree \ scratch_buffer_grow scratch_buffer_grow_preserve \ scratch_buffer_set_array_size \ dynarray_at_failure \ diff --git a/malloc/Versions b/malloc/Versions index 94c8ba8040..6693c46ee2 100644 --- a/malloc/Versions +++ b/malloc/Versions @@ -75,6 +75,7 @@ libc { __libc_thread_freeres; # struct scratch_buffer support + __libc_scratch_buffer_dupfree; __libc_scratch_buffer_grow; __libc_scratch_buffer_grow_preserve; __libc_scratch_buffer_set_array_size; diff --git a/malloc/scratch_buffer_dupfree.c b/malloc/scratch_buffer_dupfree.c new file mode 100644 index 0000000000..5561e99b0a --- /dev/null +++ b/malloc/scratch_buffer_dupfree.c @@ -0,0 +1,41 @@ +/* Variable-sized buffer with on-stack default allocation. + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _LIBC +# include +#endif + +#include +#include + +void * +__libc_scratch_buffer_dupfree (struct scratch_buffer *buffer, size_t size) +{ + void *data = buffer->data; + if (data == buffer->__space.__c) + { + void *copy = malloc (size); + return copy != NULL ? memcpy (copy, data, size) : NULL; + } + else + { + void *copy = realloc (data, size); + return copy != NULL ? copy : data; + } +} +libc_hidden_def (__libc_scratch_buffer_dupfree) diff --git a/malloc/tst-scratch_buffer.c b/malloc/tst-scratch_buffer.c index ef5fb0a8eb..6008113174 100644 --- a/malloc/tst-scratch_buffer.c +++ b/malloc/tst-scratch_buffer.c @@ -16,7 +16,10 @@ License along with the GNU C Library; if not, see . */ +#include #include +#include +#include #include #include #include @@ -148,8 +151,27 @@ do_test (void) && array_size_must_fail (4, ((size_t)-1) / 4))) return 1; } + { + struct scratch_buffer buf; + scratch_buffer_init (&buf); + memset (buf.data, '@', buf.length); + + size_t sizes[] = { 16, buf.length, buf.length + 16 }; + for (int i = 0; i < array_length (sizes); i++) + { + /* The extra size is unitialized through realloc. */ + size_t l = sizes[i] > buf.length ? sizes[i] : buf.length; + void *r = scratch_buffer_dupfree (&buf, l); + void *c = xmalloc (l); + memset (c, '@', l); + TEST_COMPARE_BLOB (r, l, buf.data, l); + free (r); + free (c); + } + + scratch_buffer_free (&buf); + } return 0; } -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include From patchwork Mon Dec 28 13:59:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1420880 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Xc3o3v3x; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D4K1v3MHKzB3vX for ; Tue, 29 Dec 2020 01:00:19 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 454343871015; Mon, 28 Dec 2020 14:00:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 454343871015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1609164000; bh=CmjILUq3e+tzu0+DoNa/P85jUVwSWxrmFynE6BdtRKc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Xc3o3v3xaeD84y5JVewQ9I5kQiYX30yRFtOol6+bUMHZOjJHWZYcReolWG2v5+Hg6 F2MCh3ufnV96sFSxJJUUhfX2irvh8yyzsOg85khhBqsml41z4w1tIwEzWdV2hWMHW6 GKW5uEXZ9EQUn7W+CCoC1U/BFhi0G494+a1o2+T8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by sourceware.org (Postfix) with ESMTPS id 0A64338708EF for ; Mon, 28 Dec 2020 13:59:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0A64338708EF Received: by mail-qv1-xf2f.google.com with SMTP id et9so4940460qvb.10 for ; Mon, 28 Dec 2020 05:59:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CmjILUq3e+tzu0+DoNa/P85jUVwSWxrmFynE6BdtRKc=; b=nWfcAqfSN9s1ywKjefyOJn4d8DHA8mFFjEmy94mTuhHuVi0YEb9XsVe0XheC5h1B8t QUihy8u2RKhIbjyeOyLNQ1C+MT75k/jtcYcDAXhkULdeJcRu3pSs9VZbJkj6ai1vPuZn HyPM3+cytF68tzSdrSlYlEEv1Ho8nF3AKTEAbCxEpwU8XFzyFfRnPzIATl0MkSbUtUO4 ohB82gDuMjMcCVlYkOVGJzF4fVUwwF24JECWo4G1dRdd6NXQ+y0RNKwT2gNo7Ao+f3Mf Kwp5lm+vVqzWZXVAK3XZyJkUf8lk8PKu4jZjtZZfBt+zpWv+NvweOrW+glPRjnUVUgoJ Pxwg== X-Gm-Message-State: AOAM532HqMDIN8tkBNDdjIajZu/QCaD/d6QVg+wjDiFCAEXQjQQ53Akd yi/Xelj1Gk4ga8vD1Q82KsE5wDiqtJPIlw== X-Google-Smtp-Source: ABdhPJzNUsoF0rYz8a+PbSM7y7/ebUxBvYtq/gFeDmy7OwI42DJJKTrVlK6iFfwPQUTDIZ4paXHZIw== X-Received: by 2002:a05:6214:1485:: with SMTP id bn5mr47614846qvb.17.1609163994888; Mon, 28 Dec 2020 05:59:54 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id i17sm24243744qtg.77.2020.12.28.05.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 05:59:54 -0800 (PST) To: libc-alpha@sourceware.org, Paul Eggert Subject: [PATCH v2 4/6] stdlib: Sync canonicalize with gnulib [BZ #10635] [BZ #26592] [BZ #26341] [BZ #24970] Date: Mon, 28 Dec 2020 10:59:42 -0300 Message-Id: <20201228135944.1018303-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201228135944.1018303-1-adhemerval.zanella@linaro.org> References: <20201228135944.1018303-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: bug-gnulib@gnu.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" It sync with gnulib version bbaba6ce5 with the following difference require fix a glibc build: --- stdlib/canonicalize.c +++ lib/canonicalize-lgpl.c @@ -52,7 +52,6 @@ # endif # define GCC_LINT 1 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) -# define FUNC_REALPATH_WORKS 1 #else # define __canonicalize_file_name canonicalize_file_name # define __realpath realpath (it is due the glibc is built with -Wundef -Werror). It fixes multiple realpath issues: - Portability fixes for errno clobbering on free (BZ#10635). The function does not call free directly anymore, although it might be done through scratch_buffer_free. The free errno clobbering is being tracked by BZ#17924. - Pointer arithmetic overflows in realpath (BZ#26592). - Realpath cyclically call __alloca(path_max) to consume too much stack space (BZ#26341). - Realpath mishandles EOVERFLOW; stat not needed anyway (BZ#24970). The check is done through faccessat now. Checked on x86_64-linux-gnu. --- stdlib/canonicalize.c | 564 ++++++++++++++++++++-------- sysdeps/unix/sysv/linux/faccessat.c | 3 +- 2 files changed, 403 insertions(+), 164 deletions(-) diff --git a/stdlib/canonicalize.c b/stdlib/canonicalize.c index 3fcb399a5d..24a027b83f 100644 --- a/stdlib/canonicalize.c +++ b/stdlib/canonicalize.c @@ -16,43 +16,212 @@ License along with the GNU C Library; if not, see . */ -#include +#ifndef _LIBC +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc + optimizes away the name == NULL test below. */ +# define _GL_ARG_NONNULL(params) + +# define _GL_USE_STDLIB_ALLOC 1 +# include +#endif + +/* Specification. */ #include -#include -#include -#include -#include + #include +#include +#include +#include #include +#include +#include +#include #include -#include +#include +#include +#include + +#ifdef _LIBC +# include +# include +# ifdef __ASSUME_FACCESSAT2 +# define FACCESSAT_NEVER_EOVERFLOWS __ASSUME_FACCESSAT2 +# else +# define FACCESSAT_NEVER_EOVERFLOWS true +# endif +# define GCC_LINT 1 +# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) +# define FUNC_REALPATH_WORKS 1 +#else +# define __canonicalize_file_name canonicalize_file_name +# define __realpath realpath +# include "pathmax.h" +# define __faccessat faccessat +# if defined _WIN32 && !defined __CYGWIN__ +# define __getcwd _getcwd +# elif HAVE_GETCWD +# if IN_RELOCWRAPPER + /* When building the relocatable program wrapper, use the system's getcwd + function, not the gnulib override, otherwise we would get a link error. + */ +# undef getcwd +# endif +# if defined VMS && !defined getcwd + /* We want the directory in Unix syntax, not in VMS syntax. + The gnulib override of 'getcwd' takes 2 arguments; the original VMS + 'getcwd' takes 3 arguments. */ +# define __getcwd(buf, max) getcwd (buf, max, 0) +# else +# define __getcwd getcwd +# endif +# else +# define __getcwd(buf, max) getwd (buf) +# endif +# define __mempcpy mempcpy +# define __pathconf pathconf +# define __rawmemchr rawmemchr +# define __readlink readlink +# define __stat stat +#endif -/* Return the canonical absolute name of file NAME. A canonical name - does not contain any `.', `..' components nor any repeated path - separators ('/') or symlinks. All path components must exist. If - RESOLVED is null, the result is malloc'd; otherwise, if the - canonical name is PATH_MAX chars or more, returns null with `errno' - set to ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, - returns the name in RESOLVED. If the name cannot be resolved and - RESOLVED is non-NULL, it contains the path of the first component - that cannot be resolved. If the path can be resolved, RESOLVED - holds the same value as the value returned. */ +/* Suppress bogus GCC -Wmaybe-uninitialized warnings. */ +#if defined GCC_LINT || defined lint +# define IF_LINT(Code) Code +#else +# define IF_LINT(Code) /* empty */ +#endif -char * -__realpath (const char *name, char *resolved) +#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT +# define DOUBLE_SLASH_IS_DISTINCT_ROOT false +#endif +#ifndef FACCESSAT_NEVER_EOVERFLOWS +# define FACCESSAT_NEVER_EOVERFLOWS false +#endif + +#if !FUNC_REALPATH_WORKS || defined _LIBC + +/* Return true if FILE's existence can be shown, false (setting errno) + otherwise. Follow symbolic links. */ +static bool +file_accessible (char const *file) +{ +# if defined _LIBC || HAVE_FACCESSAT + int r = __faccessat (AT_FDCWD, file, F_OK, AT_EACCESS); +# else + struct stat st; + int r = __stat (file, &st); +# endif + + return ((!FACCESSAT_NEVER_EOVERFLOWS && r < 0 && errno == EOVERFLOW) + || r == 0); +} + +/* True if concatenating END as a suffix to a file name means that the + code needs to check that the file name is that of a searchable + directory, since the canonicalize_filename_mode_stk code won't + check this later anyway when it checks an ordinary file name + component within END. END must either be empty, or start with a + slash. */ + +static bool _GL_ATTRIBUTE_PURE +suffix_requires_dir_check (char const *end) +{ + /* If END does not start with a slash, the suffix is OK. */ + while (ISSLASH (*end)) + { + /* Two or more slashes act like a single slash. */ + do + end++; + while (ISSLASH (*end)); + + switch (*end++) + { + default: return false; /* An ordinary file name component is OK. */ + case '\0': return true; /* Trailing "/" is trouble. */ + case '.': break; /* Possibly "." or "..". */ + } + /* Trailing "/.", or "/.." even if not trailing, is trouble. */ + if (!*end || (*end == '.' && (!end[1] || ISSLASH (end[1])))) + return true; + } + + return false; +} + +/* Append this to a file name to test whether it is a searchable directory. + On POSIX platforms "/" suffices, but "/./" is sometimes needed on + macOS 10.13 , and should also work on + platforms like AIX 7.2 that need at least "/.". */ + +#if defined _LIBC || defined LSTAT_FOLLOWS_SLASHED_SYMLINK +static char const dir_suffix[] = "/"; +#else +static char const dir_suffix[] = "/./"; +#endif + +/* Return true if DIR is a searchable dir, false (setting errno) otherwise. + DIREND points to the NUL byte at the end of the DIR string. + Store garbage into DIREND[0 .. strlen (dir_suffix)]. */ + +static bool +dir_check (char *dir, char *dirend) +{ + strcpy (dirend, dir_suffix); + return file_accessible (dir); +} + +static idx_t +get_path_max (void) +{ +# ifdef PATH_MAX + long int path_max = PATH_MAX; +# else + /* The caller invoked realpath with a null RESOLVED, even though + PATH_MAX is not defined as a constant. The glibc manual says + programs should not do this, and POSIX says the behavior is undefined. + Historically, glibc here used the result of pathconf, or 1024 if that + failed; stay consistent with this (dubious) historical practice. */ + int err = errno; + long int path_max = __pathconf ("/", _PC_PATH_MAX); + __set_errno (err); +# endif + return path_max < 0 ? 1024 : path_max <= IDX_MAX ? path_max : IDX_MAX; +} + +/* Act like __realpath (see below), with an additional argument + rname_buf that can be used as temporary storage. + + If GCC_LINT is defined, do not inline this function with GCC 10.1 + and later, to avoid creating a pointer to the stack that GCC + -Wreturn-local-addr incorrectly complains about. See: + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644 + Although the noinline attribute can hurt performance a bit, no better way + to pacify GCC is known; even an explicit #pragma does not pacify GCC. + When the GCC bug is fixed this workaround should be limited to the + broken GCC versions. */ +#if __GNUC_PREREQ (10, 1) +# if defined GCC_LINT || defined lint +__attribute__ ((__noinline__)) +# elif __OPTIMIZE__ && !__NO_INLINE__ +# define GCC_BOGUS_WRETURN_LOCAL_ADDR +# endif +#endif +static char * +realpath_stk (const char *name, char *resolved, + struct scratch_buffer *rname_buf) { - char *rpath, *dest, *extra_buf = NULL; - const char *start, *end, *rpath_limit; - long int path_max; + char *dest; + char const *start; + char const *end; int num_links = 0; if (name == NULL) { /* As per Single Unix Specification V2 we must return an error if - either parameter is a null pointer. We extend this to allow - the RESOLVED parameter to be NULL in case the we are expected to - allocate the room for the return value. */ + either parameter is a null pointer. We extend this to allow + the RESOLVED parameter to be NULL in case the we are expected to + allocate the room for the return value. */ __set_errno (EINVAL); return NULL; } @@ -60,166 +229,235 @@ __realpath (const char *name, char *resolved) if (name[0] == '\0') { /* As per Single Unix Specification V2 we must return an error if - the name argument points to an empty string. */ + the name argument points to an empty string. */ __set_errno (ENOENT); return NULL; } -#ifdef PATH_MAX - path_max = PATH_MAX; -#else - path_max = __pathconf (name, _PC_PATH_MAX); - if (path_max <= 0) - path_max = 1024; -#endif + struct scratch_buffer extra_buffer, link_buffer; + scratch_buffer_init (&extra_buffer); + scratch_buffer_init (&link_buffer); + scratch_buffer_init (rname_buf); + char *rname_on_stack = rname_buf->data; + char *rname = rname_on_stack; + bool end_in_extra_buffer = false; + bool failed = true; - if (resolved == NULL) - { - rpath = malloc (path_max); - if (rpath == NULL) - return NULL; - } - else - rpath = resolved; - rpath_limit = rpath + path_max; + /* This is always zero for Posix hosts, but can be 2 for MS-Windows + and MS-DOS X:/foo/bar file names. */ + idx_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name); - if (name[0] != '/') + if (!IS_ABSOLUTE_FILE_NAME (name)) { - if (!__getcwd (rpath, path_max)) - { - rpath[0] = '\0'; - goto error; - } - dest = __rawmemchr (rpath, '\0'); + while (!__getcwd (rname, rname_buf->length)) + { + if (errno != ERANGE) + { + dest = rname; + goto error; + } + if (!scratch_buffer_grow (rname_buf)) + goto error_nomem; + rname = rname_buf->data; + } + dest = __rawmemchr (rname, '\0'); + start = name; + prefix_len = FILE_SYSTEM_PREFIX_LEN (rname); } else { - rpath[0] = '/'; - dest = rpath + 1; + dest = __mempcpy (rname, name, prefix_len); + *dest++ = '/'; + if (DOUBLE_SLASH_IS_DISTINCT_ROOT) + { + if (prefix_len == 0 /* implies ISSLASH (name[0]) */ + && ISSLASH (name[1]) && !ISSLASH (name[2])) + *dest++ = '/'; + *dest = '\0'; + } + start = name + prefix_len; } - for (start = end = name; *start; start = end) + for ( ; *start; start = end) { - struct stat64 st; - int n; - - /* Skip sequence of multiple path-separators. */ - while (*start == '/') - ++start; - - /* Find end of path component. */ - for (end = start; *end && *end != '/'; ++end) - /* Nothing. */; - - if (end - start == 0) - break; - else if (end - start == 1 && start[0] == '.') - /* nothing */; - else if (end - start == 2 && start[0] == '.' && start[1] == '.') - { - /* Back up to previous component, ignore if at root already. */ - if (dest > rpath + 1) - while ((--dest)[-1] != '/'); - } + /* Skip sequence of multiple file name separators. */ + while (ISSLASH (*start)) + ++start; + + /* Find end of component. */ + for (end = start; *end && !ISSLASH (*end); ++end) + /* Nothing. */; + + /* Length of this file name component; it can be zero if a file + name ends in '/'. */ + idx_t startlen = end - start; + + if (startlen == 0) + break; + else if (startlen == 1 && start[0] == '.') + /* nothing */; + else if (startlen == 2 && start[0] == '.' && start[1] == '.') + { + /* Back up to previous component, ignore if at root already. */ + if (dest > rname + prefix_len + 1) + for (--dest; dest > rname && !ISSLASH (dest[-1]); --dest) + continue; + if (DOUBLE_SLASH_IS_DISTINCT_ROOT + && dest == rname + 1 && !prefix_len + && ISSLASH (*dest) && !ISSLASH (dest[1])) + dest++; + } else - { - size_t new_size; - - if (dest[-1] != '/') - *dest++ = '/'; - - if (dest + (end - start) >= rpath_limit) - { - ptrdiff_t dest_offset = dest - rpath; - char *new_rpath; - - if (resolved) - { - __set_errno (ENAMETOOLONG); - if (dest > rpath + 1) - dest--; - *dest = '\0'; - goto error; - } - new_size = rpath_limit - rpath; - if (end - start + 1 > path_max) - new_size += end - start + 1; - else - new_size += path_max; - new_rpath = (char *) realloc (rpath, new_size); - if (new_rpath == NULL) - goto error; - rpath = new_rpath; - rpath_limit = rpath + new_size; - - dest = rpath + dest_offset; - } - - dest = __mempcpy (dest, start, end - start); - *dest = '\0'; - - if (__lstat64 (rpath, &st) < 0) - goto error; - - if (S_ISLNK (st.st_mode)) - { - char *buf = __alloca (path_max); - size_t len; - - if (++num_links > __eloop_threshold ()) - { - __set_errno (ELOOP); - goto error; - } - - n = __readlink (rpath, buf, path_max - 1); - if (n < 0) - goto error; - buf[n] = '\0'; - - if (!extra_buf) - extra_buf = __alloca (path_max); - - len = strlen (end); - if (path_max - n <= len) - { - __set_errno (ENAMETOOLONG); - goto error; - } - - /* Careful here, end may be a pointer into extra_buf... */ - memmove (&extra_buf[n], end, len + 1); - name = end = memcpy (extra_buf, buf, n); - - if (buf[0] == '/') - dest = rpath + 1; /* It's an absolute symlink */ - else - /* Back up to previous component, ignore if at root already: */ - if (dest > rpath + 1) - while ((--dest)[-1] != '/'); - } - else if (!S_ISDIR (st.st_mode) && *end != '\0') - { - __set_errno (ENOTDIR); - goto error; - } - } + { + if (!ISSLASH (dest[-1])) + *dest++ = '/'; + + while (rname + rname_buf->length - dest + < startlen + sizeof dir_suffix) + { + idx_t dest_offset = dest - rname; + if (!scratch_buffer_grow_preserve (rname_buf)) + goto error_nomem; + rname = rname_buf->data; + dest = rname + dest_offset; + } + + dest = __mempcpy (dest, start, startlen); + *dest = '\0'; + + char *buf; + ssize_t n; + while (true) + { + buf = link_buffer.data; + idx_t bufsize = link_buffer.length; + n = __readlink (rname, buf, bufsize - 1); + if (n < bufsize - 1) + break; + if (!scratch_buffer_grow (&link_buffer)) + goto error_nomem; + } + if (0 <= n) + { + if (++num_links > __eloop_threshold ()) + { + __set_errno (ELOOP); + goto error; + } + + buf[n] = '\0'; + + char *extra_buf = extra_buffer.data; + idx_t end_idx IF_LINT (= 0); + if (end_in_extra_buffer) + end_idx = end - extra_buf; + idx_t len = strlen (end); + while (extra_buffer.length <= len + n) + { + if (!scratch_buffer_grow_preserve (&extra_buffer)) + goto error_nomem; + extra_buf = extra_buffer.data; + } + if (end_in_extra_buffer) + end = extra_buf + end_idx; + + /* Careful here, end may be a pointer into extra_buf... */ + memmove (&extra_buf[n], end, len + 1); + name = end = memcpy (extra_buf, buf, n); + end_in_extra_buffer = true; + + if (IS_ABSOLUTE_FILE_NAME (buf)) + { + idx_t pfxlen = FILE_SYSTEM_PREFIX_LEN (buf); + + dest = __mempcpy (rname, buf, pfxlen); + *dest++ = '/'; /* It's an absolute symlink */ + if (DOUBLE_SLASH_IS_DISTINCT_ROOT) + { + if (ISSLASH (buf[1]) && !ISSLASH (buf[2]) && !pfxlen) + *dest++ = '/'; + *dest = '\0'; + } + /* Install the new prefix to be in effect hereafter. */ + prefix_len = pfxlen; + } + else + { + /* Back up to previous component, ignore if at root + already: */ + if (dest > rname + prefix_len + 1) + for (--dest; dest > rname && !ISSLASH (dest[-1]); --dest) + continue; + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1 + && ISSLASH (*dest) && !ISSLASH (dest[1]) && !prefix_len) + dest++; + } + } + else if (! (suffix_requires_dir_check (end) + ? dir_check (rname, dest) + : errno == EINVAL)) + goto error; + } } - if (dest > rpath + 1 && dest[-1] == '/') + if (dest > rname + prefix_len + 1 && ISSLASH (dest[-1])) --dest; - *dest = '\0'; - - assert (resolved == NULL || resolved == rpath); - return rpath; + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1 && !prefix_len + && ISSLASH (*dest) && !ISSLASH (dest[1])) + dest++; + failed = false; error: - assert (resolved == NULL || resolved == rpath); - if (resolved == NULL) - free (rpath); - return NULL; + *dest++ = '\0'; + if (resolved != NULL && dest - rname <= get_path_max ()) + rname = strcpy (resolved, rname); + +error_nomem: + scratch_buffer_free (&extra_buffer); + scratch_buffer_free (&link_buffer); + if (failed || rname == resolved) + scratch_buffer_free (rname_buf); + + if (failed) + return NULL; + + if (rname == resolved) + return rname; + idx_t rname_size = dest - rname; + if (rname == rname_on_stack) + { + rname = malloc (rname_size); + if (rname == NULL) + return NULL; + return memcpy (rname, rname_on_stack, rname_size); + } + char *result = realloc (rname, rname_size); + return result != NULL ? result : rname; +} + +/* Return the canonical absolute name of file NAME. A canonical name + does not contain any ".", ".." components nor any repeated file name + separators ('/') or symlinks. All file name components must exist. If + RESOLVED is null, the result is malloc'd; otherwise, if the + canonical name is PATH_MAX chars or more, returns null with 'errno' + set to ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, + returns the name in RESOLVED. If the name cannot be resolved and + RESOLVED is non-NULL, it contains the name of the first component + that cannot be resolved. If the name can be resolved, RESOLVED + holds the same value as the value returned. */ + +char * +__realpath (const char *name, char *resolved) +{ + #ifdef GCC_BOGUS_WRETURN_LOCAL_ADDR + #warning "GCC might issue a bogus -Wreturn-local-addr warning here." + #warning "See ." + #endif + struct scratch_buffer rname_buffer; + return realpath_stk (name, resolved, &rname_buffer); } libc_hidden_def (__realpath) versioned_symbol (libc, __realpath, realpath, GLIBC_2_3); +#endif /* !FUNC_REALPATH_WORKS || defined _LIBC */ #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3) diff --git a/sysdeps/unix/sysv/linux/faccessat.c b/sysdeps/unix/sysv/linux/faccessat.c index 5d078371b5..5bb1051c06 100644 --- a/sysdeps/unix/sysv/linux/faccessat.c +++ b/sysdeps/unix/sysv/linux/faccessat.c @@ -24,7 +24,7 @@ int -faccessat (int fd, const char *file, int mode, int flag) +__faccessat (int fd, const char *file, int mode, int flag) { int ret = INLINE_SYSCALL_CALL (faccessat2, fd, file, mode, flag); #if __ASSUME_FACCESSAT2 @@ -73,3 +73,4 @@ faccessat (int fd, const char *file, int mode, int flag) return INLINE_SYSCALL_ERROR_RETURN_VALUE (EACCES); #endif /* !__ASSUME_FACCESSAT2 */ } +weak_alias (__faccessat, faccessat) From patchwork Mon Dec 28 13:59:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1420879 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=vmPmJC9i; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D4K1p3sSPzB3tX for ; Tue, 29 Dec 2020 01:00:14 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B305F3870905; Mon, 28 Dec 2020 13:59:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B305F3870905 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1609163998; bh=MhYux0mFjOVWrrC/XqAaF4aF5bg3rny5qdfZpnJw44E=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=vmPmJC9iWPaVGS8oggaVa0f0OUjlqF9aooz2duOVfYGSe1buzRn4m6L06S2QYHxd7 lRxlfLMsEvgw7KXcC5SlRu0S1P6SASgdhWGoyPuofy1wBf+Ns/SRm3xbcD0BbqB+sN 3iSRHr0h77UC1WT39pMd/0TzdWh//thagZz/9kys= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by sourceware.org (Postfix) with ESMTPS id 4F7263840C34 for ; Mon, 28 Dec 2020 13:59:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4F7263840C34 Received: by mail-qk1-x735.google.com with SMTP id 22so8784607qkf.9 for ; Mon, 28 Dec 2020 05:59:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MhYux0mFjOVWrrC/XqAaF4aF5bg3rny5qdfZpnJw44E=; b=ogU/ZVCXFyo8V9+eF2kTj5sXqDk9tvuHdDO/9rl+2eTMu1/goqpPi4LWaNMgdmPpyq HjbpArTO0gyEfNXd/4Qudsgxwk+fO+7jYIVx/xgLEaK2rWa3eKUuQ10lAxwWY4Dcd59g Bh5n250bEXNjJ08OhkvKhEjd/llGWovyrNafyCbi5FjLzKWgiajOyTy4VOQCUNz49eT1 AEXZsw87e9dkgYTEYByLlMEzpkMjXWuYf/KfoL9e2K4AfLYXZBGiPWG1xOX8umbi7z7C 6/IcMROxRbD4d8KaP+BTU1QsUTrcouLpYEWoUsGzvbf3RPPyOWDS3eALhH3Gx8n5zs6a AHdg== X-Gm-Message-State: AOAM533qwka8hPceuR/m282jGDQKfmg7tnKHEZLGwJt4d6M6uYLcUnIt WeExZWo0gX8vaEJKn7KfRiVZTSuLxUBxrA== X-Google-Smtp-Source: ABdhPJz9IhoSZH5qK5YW8Rm7LD+EmMAFplrj9PB28RFvcBb4N/oYRpuVaCSd4s04yMT9B1PgXewpZQ== X-Received: by 2002:a37:4e50:: with SMTP id c77mr43719000qkb.252.1609163996755; Mon, 28 Dec 2020 05:59:56 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id i17sm24243744qtg.77.2020.12.28.05.59.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 05:59:56 -0800 (PST) To: libc-alpha@sourceware.org, Paul Eggert Subject: [PATCH v2 5/6] stdlibc: Simplify realpath via scratch_buffer_dupfree Date: Mon, 28 Dec 2020 10:59:43 -0300 Message-Id: <20201228135944.1018303-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201228135944.1018303-1-adhemerval.zanella@linaro.org> References: <20201228135944.1018303-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: bug-gnulib@gnu.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" From: Paul Eggert Checked on x86_64-linux-gnu. --- stdlib/canonicalize.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/stdlib/canonicalize.c b/stdlib/canonicalize.c index 24a027b83f..69f978da78 100644 --- a/stdlib/canonicalize.c +++ b/stdlib/canonicalize.c @@ -414,24 +414,14 @@ error: error_nomem: scratch_buffer_free (&extra_buffer); scratch_buffer_free (&link_buffer); - if (failed || rname == resolved) - scratch_buffer_free (rname_buf); - - if (failed) - return NULL; - if (rname == resolved) - return rname; - idx_t rname_size = dest - rname; - if (rname == rname_on_stack) + if (failed || rname == resolved) { - rname = malloc (rname_size); - if (rname == NULL) - return NULL; - return memcpy (rname, rname_on_stack, rname_size); + scratch_buffer_free (rname_buf); + return failed ? NULL : resolved; } - char *result = realloc (rname, rname_size); - return result != NULL ? result : rname; + + return scratch_buffer_dupfree (rname_buf, dest - rname); } /* Return the canonical absolute name of file NAME. A canonical name From patchwork Mon Dec 28 13:59:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1420881 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=CRQOsI6k; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D4K215vbZzB3tV for ; Tue, 29 Dec 2020 01:00:25 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 66CA7383F84D; Mon, 28 Dec 2020 14:00:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 66CA7383F84D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1609164001; bh=LmQg2lOefaynJUHiCfMOninl/m1Oi/ewIzM+z4j8Rso=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=CRQOsI6ki+ZD9lmPTktX3BfmoE/8aQtnaOXtE3Ur0jNEYqtyu87jmPny8jkLCMFp1 aNz+6UccTQl7AhkaP13DyUesiOXIO/9adwN/mXL9qeCds8TKUhdN7b9gd3TNCJymbQ jThK3OwDjueT0bo3tKjaYwu7C/Lbu3xXR+ur4V5Y= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by sourceware.org (Postfix) with ESMTPS id 0863038708EF for ; Mon, 28 Dec 2020 13:59:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0863038708EF Received: by mail-qk1-x731.google.com with SMTP id 143so8778824qke.10 for ; Mon, 28 Dec 2020 05:59:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LmQg2lOefaynJUHiCfMOninl/m1Oi/ewIzM+z4j8Rso=; b=K1y1F/asShmTpEjZkFl0ykaEzZXoRRMwNLEWHEvzRGoYa1qGQUkNx/HSpQILaxVqru RlXFvqFZDpeKluUDwiNPZ9iSDg0VwwDV2vjIEYbj49fJjn/NHwZ7rje+Pvg3BbLuojz5 RGy02QwQ73KVl92OX4aCww/6afG3SecqxDC6BVjHw8Ss80UZx7NB8sL5RyZ/5AA/zrdA TRBo7Xg/9bOWAQnlgOSj+1oF+iXqdMgtYwRyUeqi0w8Em7snP5hybtj6TahlPyXuxCYK Abe34H3qJ2idXpqVByIYNTU3s2eT2mPh2XB6O81cXblUSCwv/tV6yO8gobOPtUave3Jl bP+g== X-Gm-Message-State: AOAM531tCOYnz7AIk1PWIC4HoQwcHtAypqxXbqtu/r9H0mgSXx5Pb33r RAdLit/PrBp3XHP5HDNX3gPVwRm7oX4BZA== X-Google-Smtp-Source: ABdhPJzLzxfLKRFtEs6HqqrqhDQD0uIvpxNlLdfDV40dOMPwxOM+3Y/nu0p0OUG2max13P4YhZD6LA== X-Received: by 2002:a37:9d0e:: with SMTP id g14mr43952432qke.125.1609163998461; Mon, 28 Dec 2020 05:59:58 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id i17sm24243744qtg.77.2020.12.28.05.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 05:59:58 -0800 (PST) To: libc-alpha@sourceware.org, Paul Eggert Subject: [PATCH v2 6/6] stdlib: Assume FACCESSAT_NEVER_EOVERFLOWS on realpath Date: Mon, 28 Dec 2020 10:59:44 -0300 Message-Id: <20201228135944.1018303-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201228135944.1018303-1-adhemerval.zanella@linaro.org> References: <20201228135944.1018303-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: bug-gnulib@gnu.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The faccessat (..., AT_EACCESS) on Linux fallback will either use __NR_faccessat for __libc_enable_secure or LFS fstatat call. Neither fallbacks returns EOVERFLOW in failure case. Checked on x86_64-linux-gnu. --- stdlib/canonicalize.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/stdlib/canonicalize.c b/stdlib/canonicalize.c index 69f978da78..5aac8d457c 100644 --- a/stdlib/canonicalize.c +++ b/stdlib/canonicalize.c @@ -44,15 +44,10 @@ #ifdef _LIBC # include -# include -# ifdef __ASSUME_FACCESSAT2 -# define FACCESSAT_NEVER_EOVERFLOWS __ASSUME_FACCESSAT2 -# else -# define FACCESSAT_NEVER_EOVERFLOWS true -# endif # define GCC_LINT 1 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) # define FUNC_REALPATH_WORKS 1 +# define FACCESSAT_NEVER_EOVERFLOWS true #else # define __canonicalize_file_name canonicalize_file_name # define __realpath realpath @@ -82,7 +77,7 @@ # define __pathconf pathconf # define __rawmemchr rawmemchr # define __readlink readlink -# define __stat stat +# define FACCESSAT_NEVER_EOVERFLOWS false #endif /* Suppress bogus GCC -Wmaybe-uninitialized warnings. */ @@ -95,9 +90,6 @@ #ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT # define DOUBLE_SLASH_IS_DISTINCT_ROOT false #endif -#ifndef FACCESSAT_NEVER_EOVERFLOWS -# define FACCESSAT_NEVER_EOVERFLOWS false -#endif #if !FUNC_REALPATH_WORKS || defined _LIBC