diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-04-12 17:39:01 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-04-12 18:36:26 +0200 |
| commit | 08ca4d22e08491130bd6be4baad4503f972f7750 (patch) | |
| tree | 22ffe3407153e94641806c85850d7287fce83ce4 /sam.c | |
| parent | e5e372ce62f36589ee6b6bc7cb8fd07dfcfb3696 (diff) | |
| download | vis-08ca4d22e08491130bd6be4baad4503f972f7750.tar.gz vis-08ca4d22e08491130bd6be4baad4503f972f7750.tar.xz | |
sam: reject command names containing digits or ending with a hyphen
The current implementation will also reject consecutive hyphens.
Diffstat (limited to 'sam.c')
| -rw-r--r-- | sam.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -605,12 +605,17 @@ static void parse_argv(const char **s, const char *argv[], size_t maxarg) { } } +static bool valid_cmdname(const char *s) { + unsigned char c = (unsigned char)*s; + return c && !isspace(c) && !isdigit(c) && (!ispunct(c) || (c == '-' && valid_cmdname(s+1))); +} + static char *parse_cmdname(const char **s) { Buffer buf; buffer_init(&buf); skip_spaces(s); - while (**s && !isspace((unsigned char)**s) && (!ispunct((unsigned char)**s) || **s == '-')) + while (valid_cmdname(*s)) buffer_append(&buf, (*s)++, 1); buffer_terminate(&buf); |
