From: Bruno Haible Date: Fri, 2 Apr 2021 15:34:46 +0000 (+0200) Subject: glob: Reject ~user syntax, when flag GLOB_TILDE_CHECK is given. X-Git-Tag: v1.0~2995 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=38d0749a3077b03fda46567510b1217fb5e4e170;p=gnulib.git glob: Reject ~user syntax, when flag GLOB_TILDE_CHECK is given. Reported and patch suggested by Eli Zaretskii in . * lib/glob.c (__glob) [WINDOWS32]: If flag GLOB_TILDE_CHECK is given, do error handling like when ~user is allowed by the user is unknown. --- diff --git a/ChangeLog b/ChangeLog index 784409dba9..f4e766f8f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2021-04-02 Bruno Haible + + glob: Reject ~user syntax, when flag GLOB_TILDE_CHECK is given. + Reported and patch suggested by Eli Zaretskii in + . + * lib/glob.c (__glob) [WINDOWS32]: If flag GLOB_TILDE_CHECK is given, do + error handling like when ~user is allowed by the user is unknown. + 2021-03-31 Paul Eggert xalloc: delay setting size until success diff --git a/lib/glob.c b/lib/glob.c index 775911ef5b..e148f8d761 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -743,6 +743,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; @@ -881,7 +883,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 */ } }