]> Savannah Git Hosting - gnulib.git/commitdiff
glob: Reject ~user syntax, when flag GLOB_TILDE_CHECK is given.
authorBruno Haible <bruno@clisp.org>
Fri, 2 Apr 2021 15:34:46 +0000 (17:34 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 2 Apr 2021 15:34:46 +0000 (17:34 +0200)
Reported and patch suggested by Eli Zaretskii <eliz@gnu.org> in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00136.html>.

* 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.

ChangeLog
lib/glob.c

index 784409dba9c9d3747fa0cc7e17f58d6fdbb1eddf..f4e766f8f5e2832f5e1b2c9fcf9856a4f7616ebf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2021-04-02  Bruno Haible  <bruno@clisp.org>
+
+       glob: Reject ~user syntax, when flag GLOB_TILDE_CHECK is given.
+       Reported and patch suggested by Eli Zaretskii <eliz@gnu.org> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00136.html>.
+       * 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  <eggert@cs.ucla.edu>
 
        xalloc: delay setting size until success
index 775911ef5b74fe3d85a514b0670c80066178695a..e148f8d761d8012dd8be3c22eac93b1ae6c96b08 100644 (file)
@@ -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 */
         }
     }