From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 04C603858D28 for ; Wed, 27 Apr 2022 21:16:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 04C603858D28 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-349-b20bbUZSMC-W7VE2INyFZA-1; Wed, 27 Apr 2022 17:16:17 -0400 X-MC-Unique: b20bbUZSMC-W7VE2INyFZA-1 Received: by mail-qk1-f198.google.com with SMTP id u7-20020ae9d807000000b00680a8111ef6so1952797qkf.17 for ; Wed, 27 Apr 2022 14:16:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=T3CS50mMJxIUFprvZDLK0EP4Wk+scKoCBFniXZeK5n8=; b=mrMexqMQh8Cm5VLhqE//I4tfjP3ALVGFC8uDpjvDLh8mblXjJleB6y+XkZAygCwDGf Mlfl9wg2q4eL24yo7Hat8q9uZJ+ru1Bd7OArmNuL0834hDVlik1yBAcWhQEsEBQZXVRg YeWomg4np+5x4j0kitMGHO9UPNPElLV77P5mxwq6DADDz+8UylNkmHzZ4Rc2UxlMdL5t 9VGSOFCwzV1I+0T9GsR8oV1694FGXmufLVkEnkYD3096ZtN4xgbJkFCmtIPcSHW+Q/94 hEFOkNnnQJ4PDm2yX88aRqpFY7EBttOWjLQ+xcN6LDMVmx1sUrmP70IezEWUriRTcLOX Mvtw== X-Gm-Message-State: AOAM532+Oi/Koe4bR4AjAXu+sotM04FGxMn6en25V44cT+WcLXzej5XY 1w74yMXsZqGNr20LUFUMhjCVH0PiwXk/509rAXzQ0jlaEDkmuNYPk9Ncw9rXtVuFZmLuGpy8T1a G/KQwKb1BuRe/NHNTCKAE X-Received: by 2002:a37:b741:0:b0:69e:689f:7639 with SMTP id h62-20020a37b741000000b0069e689f7639mr16853389qkf.160.1651094176476; Wed, 27 Apr 2022 14:16:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCPvuvETZAN6MPk77VCzoKIDepHWr78pcZt6x+dGQfhWQJOIDu1qSxuAXSv7vJKMI0dKiESA== X-Received: by 2002:a37:b741:0:b0:69e:689f:7639 with SMTP id h62-20020a37b741000000b0069e689f7639mr16853378qkf.160.1651094176187; Wed, 27 Apr 2022 14:16:16 -0700 (PDT) Received: from [192.168.0.241] (135-23-175-80.cpe.pppoe.ca. [135.23.175.80]) by smtp.gmail.com with ESMTPSA id t186-20020a372dc3000000b0069ec8a9254esm8737073qkh.73.2022.04.27.14.16.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Apr 2022 14:16:15 -0700 (PDT) Message-ID: <7338a6b9-a940-7647-e716-a1b65fd62023@redhat.com> Date: Wed, 27 Apr 2022 17:16:14 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [v3] posix/glob.c: update from gnulib To: DJ Delorie , libc-alpha@sourceware.org References: From: Carlos O'Donell Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Wed, 27 Apr 2022 21:16:22 -0000 On 4/14/22 19:40, DJ Delorie wrote: > > [v3: Added sysdeps/unix/sysv/linux/glob64-time64.c to fix i686 build] > > Copied from gnulib/lib/glob.c in order to fix rhbz 1982608 > Also fixes swbz 25659 Passes CI/CD. Passes without regression on x86_64. Minor difference from upstream gnulib. LGTM. Thank you! Reviewed-by: Carlos O'Donell Tested-by: Carlos O'Donell > diff --git a/posix/glob.c b/posix/glob.c > index a2b5aabada..f6993a3706 100644 > --- a/posix/glob.c > +++ b/posix/glob.c > @@ -21,13 +21,14 @@ > optimizes away the pattern == NULL test below. */ > # define _GL_ARG_NONNULL(params) > > -# include > +# include > > #endif > > #include > > #include > +#include > #include > #include > #include > @@ -56,6 +57,8 @@ > # define sysconf(id) __sysconf (id) > # define closedir(dir) __closedir (dir) > # define opendir(name) __opendir (name) > +# undef dirfd > +# define dirfd(str) __dirfd (str) > # define readdir(str) __readdir64 (str) > # define getpwnam_r(name, bufp, buf, len, res) \ > __getpwnam_r (name, bufp, buf, len, res) > @@ -69,11 +72,8 @@ > # ifndef GLOB_LSTAT > # define GLOB_LSTAT gl_lstat > # endif > -# ifndef GLOB_STAT64 > -# define GLOB_STAT64 __stat64 > -# endif > -# ifndef GLOB_LSTAT64 > -# define GLOB_LSTAT64 __lstat64 > +# ifndef GLOB_FSTATAT64 > +# define GLOB_FSTATAT64 __fstatat64 > # endif > # include > #else /* !_LIBC */ > @@ -88,8 +88,7 @@ > # define struct_stat struct stat > # define struct_stat64 struct stat > # define GLOB_LSTAT gl_lstat > -# define GLOB_STAT64 stat > -# define GLOB_LSTAT64 lstat > +# define GLOB_FSTATAT64 fstatat > #endif /* _LIBC */ > > #include > @@ -215,7 +214,8 @@ glob_lstat (glob_t *pglob, int flags, const char *fullname) > } ust; > return (__glibc_unlikely (flags & GLOB_ALTDIRFUNC) > ? pglob->GLOB_LSTAT (fullname, &ust.st) > - : GLOB_LSTAT64 (fullname, &ust.st64)); > + : GLOB_FSTATAT64 (AT_FDCWD, fullname, &ust.st64, > + AT_SYMLINK_NOFOLLOW)); > } > > /* Set *R = A + B. Return true if the answer is mathematically > @@ -257,7 +257,8 @@ is_dir (char const *filename, int flags, glob_t const *pglob) > struct_stat64 st64; > return (__glibc_unlikely (flags & GLOB_ALTDIRFUNC) > ? pglob->gl_stat (filename, &st) == 0 && S_ISDIR (st.st_mode) > - : GLOB_STAT64 (filename, &st64) == 0 && S_ISDIR (st64.st_mode)); > + : (GLOB_FSTATAT64 (AT_FDCWD, filename, &st64, 0) == 0 > + && S_ISDIR (st64.st_mode))); > } > > /* Find the end of the sub-pattern in a brace expression. */ > @@ -747,6 +748,8 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int), > else > { > #ifndef WINDOWS32 > + /* Recognize ~user as a shorthand for the specified user's home > + directory. */ > char *end_name = strchr (dirname, '/'); > char *user_name; > int malloc_user_name = 0; > @@ -885,7 +888,22 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int), > } > scratch_buffer_free (&pwtmpbuf); > } > -#endif /* !WINDOWS32 */ > +#else /* WINDOWS32 */ > + /* On native Windows, access to a user's home directory > + (via GetUserProfileDirectory) or to a user's environment > + variables (via ExpandEnvironmentStringsForUser) requires > + the credentials of the user. Therefore we cannot support > + the ~user syntax on this platform. > + Handling ~user specially (and treat it like plain ~) if > + user is getenv ("USERNAME") would not be a good idea, > + since it would make people think that ~user is supported > + in general. */ > + if (flags & GLOB_TILDE_CHECK) > + { > + retval = GLOB_NOMATCH; > + goto out; > + } > +#endif /* WINDOWS32 */ > } > } > > @@ -1266,6 +1284,8 @@ glob_in_dir (const char *pattern, const char *directory, int flags, > { > size_t dirlen = strlen (directory); > void *stream = NULL; > + struct scratch_buffer s; > + scratch_buffer_init (&s); > # define GLOBNAMES_MEMBERS(nnames) \ > struct globnames *next; size_t count; char *name[nnames]; > struct globnames { GLOBNAMES_MEMBERS (FLEXIBLE_ARRAY_MEMBER) }; > @@ -1337,6 +1357,7 @@ glob_in_dir (const char *pattern, const char *directory, int flags, > } > else > { > + int dfd = dirfd (stream); > int fnm_flags = ((!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0) > | ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0)); > flags |= GLOB_MAGCHAR; > @@ -1364,8 +1385,32 @@ glob_in_dir (const char *pattern, const char *directory, int flags, > if (flags & GLOB_ONLYDIR) > switch (readdir_result_type (d)) > { > - case DT_DIR: case DT_LNK: case DT_UNKNOWN: break; > default: continue; > + case DT_DIR: break; > + case DT_LNK: case DT_UNKNOWN: > + /* The filesystem was too lazy to give us a hint, > + so we have to do it the hard way. */ > + if (__glibc_unlikely (dfd < 0 || flags & GLOB_ALTDIRFUNC)) > + { > + size_t namelen = strlen (d.name); > + size_t need = dirlen + 1 + namelen + 1; > + if (s.length < need > + && !scratch_buffer_set_array_size (&s, need, 1)) > + goto memory_error; > + char *p = mempcpy (s.data, directory, dirlen); > + *p = '/'; > + p += p[-1] != '/'; > + memcpy (p, d.name, namelen + 1); > + if (! is_dir (s.data, flags, pglob)) > + continue; > + } > + else > + { > + struct_stat64 st64; > + if (! (GLOB_FSTATAT64 (dfd, d.name, &st64, 0) == 0 > + && S_ISDIR (st64.st_mode))) > + continue; > + } > } > > if (fnmatch (pattern, d.name, fnm_flags) == 0) > @@ -1497,5 +1542,6 @@ glob_in_dir (const char *pattern, const char *directory, int flags, > __set_errno (save); > } > > + scratch_buffer_free (&s); > return result; > } > diff --git a/sysdeps/unix/sysv/linux/glob64-time64.c b/sysdeps/unix/sysv/linux/glob64-time64.c > index 32b4929a1b..1d485dc806 100644 > --- a/sysdeps/unix/sysv/linux/glob64-time64.c > +++ b/sysdeps/unix/sysv/linux/glob64-time64.c > @@ -37,6 +37,7 @@ > # define GLOB_LSTAT gl_lstat > # define GLOB_STAT64 __stat64_time64 > # define GLOB_LSTAT64 __lstat64_time64 > +# define GLOB_FSTATAT64 __fstatat64_time64 > > # define COMPILE_GLOB64 1 > > -- Cheers, Carlos.