From 05b1f8423daae61cd344e810bf101124c19d2589 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Mon, 12 Sep 2016 13:47:46 +1000 Subject: [PATCH] * try to fix parsing of 'jail regex add ' --- src/commands.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/commands.c b/src/commands.c index 2d62454..bb4ac5c 100644 --- a/src/commands.c +++ b/src/commands.c @@ -169,8 +169,17 @@ f2b_cmd_parse(const char *src, char *buf, size_t buflen) { if (tokenc == 4 && strcmp(tokens[2], "regex") == 0 && strcmp(tokens[3], "stats") == 0) { return CMD_JAIL_REGEX_STATS; } - if (tokenc == 5 && strcmp(tokens[2], "regex") == 0 && strcmp(tokens[3], "add") == 0) { - strlcat(buf, tokens[4], buflen); + if (tokenc >= 5 && strcmp(tokens[2], "regex") == 0 && strcmp(tokens[3], "add") == 0) { + /* TODO: rewrite, this version is very error-prone */ + char *regex = strstr(src, "add"); + regex += strlen("add"); + while (isblank(*regex)) + regex++; + if (*regex == '\0') { + /* empty regex */ + return CMD_NONE; + } + strlcat(buf, regex, buflen); strlcat(buf, "\n", buflen); return CMD_JAIL_REGEX_ADD; }