From 08ca4d22e08491130bd6be4baad4503f972f7750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 12 Apr 2017 17:39:01 +0200 Subject: sam: reject command names containing digits or ending with a hyphen The current implementation will also reject consecutive hyphens. --- sam.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sam.c b/sam.c index fbfb0d1..e2e1667 100644 --- a/sam.c +++ b/sam.c @@ -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); -- cgit v1.2.3