fix path expansion to accept valid POSIX usernames
authorManzur Mukhitdinov <manzurmm@gmail.com>
Sat, 12 Nov 2016 19:16:20 +0000 (20:16 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Sat, 19 Nov 2016 21:31:36 +0000 (22:31 +0100)
To be portable across systems conforming to POSIX.1-2008, the
username is composed of characters from the portable filename character
set([A-Za-z._-])[1][2].

The <hyphen-minus> character should not be used as the first
character of a portable user name.

Links:
[1] Username format:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_435

[2] Portable filename character set:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282

src/ascii.h
src/util.c

index 4e37036..ff1e213 100644 (file)
@@ -60,16 +60,17 @@ static const unsigned char chartable[256] = {
 #undef C
 #undef SC
 
-#define VB_IS_UPPER(c)     ((chartable[(unsigned char)c] & VB_UPPER) != 0)
-#define VB_IS_LOWER(c)     ((chartable[(unsigned char)c] & VB_LOWER) != 0)
-#define VB_IS_DIGIT(c)     ((chartable[(unsigned char)c] & VB_DIGIT) != 0)
-#define VB_IS_PUNKT(c)     ((chartable[(unsigned char)c] & VB_PUNKT) != 0)
-#define VB_IS_SPACE(c)     ((chartable[(unsigned char)c] & VB_SPACE) != 0)
-#define VB_IS_CTRL(c)      ((chartable[(unsigned char)c] & VB_CTRL) != 0)
-#define VB_IS_SEPARATOR(c) (VB_IS_SPACE(c) || c == '"' || c == '\'')
-#define VB_IS_ALPHA(c)     (VB_IS_LOWER(c) || VB_IS_UPPER(c))
-#define VB_IS_ALNUM(c)     (VB_IS_ALPHA(c) || VB_IS_DIGIT(c))
-#define VB_IS_IDENT(c)     (VB_IS_ALNUM(c) || c == '_')
+#define VB_IS_UPPER(c)      ((chartable[(unsigned char)c] & VB_UPPER) != 0)
+#define VB_IS_LOWER(c)      ((chartable[(unsigned char)c] & VB_LOWER) != 0)
+#define VB_IS_DIGIT(c)      ((chartable[(unsigned char)c] & VB_DIGIT) != 0)
+#define VB_IS_PUNKT(c)      ((chartable[(unsigned char)c] & VB_PUNKT) != 0)
+#define VB_IS_SPACE(c)      ((chartable[(unsigned char)c] & VB_SPACE) != 0)
+#define VB_IS_CTRL(c)       ((chartable[(unsigned char)c] & VB_CTRL) != 0)
+#define VB_IS_SEPARATOR(c)  (VB_IS_SPACE(c) || c == '"' || c == '\'')
+#define VB_IS_ALPHA(c)      (VB_IS_LOWER(c) || VB_IS_UPPER(c))
+#define VB_IS_ALNUM(c)      (VB_IS_ALPHA(c) || VB_IS_DIGIT(c))
+#define VB_IS_IDENT(c)      (VB_IS_ALNUM(c) || c == '_')
+#define VB_IS_USER_IDENT(c) (VB_IS_IDENT(c) || c == '-' || c == '.')
 
 /* CSI (control sequence introducer) is the first byte of a control sequence
  * and is always followed by two bytes. */
index 447f782..34b6c81 100644 (file)
@@ -489,12 +489,12 @@ gboolean util_parse_expansion(const char **input, GString *str, int flags,
             if (!*(*input + 1) || VB_IS_SPACE(*(*input + 1))) {
                 (*input)++;
             }
-        } else {
+        } else if (**input != '-') {
             /* look ahead to / space or end of string to get a possible
              * username for ~user pattern */
             name = g_string_new("");
             /* current char is ~ that is skipped to get the user name */
-            while (VB_IS_IDENT(**input)) {
+            while (VB_IS_USER_IDENT(**input)) {
                 g_string_append_c(name, **input);
                 (*input)++;
             }