From 3a4c7107d682b4219cc87a696ecfe3a6095512be Mon Sep 17 00:00:00 2001 From: tslil clingman Date: Wed, 6 Oct 2021 08:50:27 -0400 Subject: Enforce quoted ptn string for geminict --- src/geminict.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/geminict.c') diff --git a/src/geminict.c b/src/geminict.c index 2ac2eab..d25b40c 100644 --- a/src/geminict.c +++ b/src/geminict.c @@ -311,8 +311,29 @@ int main(int argc, char **argv) { char* line = argv[1]; // Some maximum length we're willing to parse - const uint32_t len = strnlen(line, 65535); - if (!line || len == 0 || len == 65535) return EXIT_FAILURE; + uint32_t len = strnlen(line, 65535); + if (!line || len < 2 || len == 65535) { + puts("Malformed input."); + return EXIT_FAILURE; + } + + // strip quotes + if (line[0]=='\'') { + line++; + len--; + } else { + puts("Malformed input."); + return EXIT_FAILURE; + } + + if (line[len-1]=='\'') { + line[len-1]=0; + len--; + } else { + puts("Malformed input."); + return EXIT_FAILURE; + } + uint32_t start = 0, end = 0; while (start < len) { // Find first separator -- cgit v1.2.3