From 90b80aba898cc68e18a42270223e520b880f6427 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 1 Oct 2018 02:26:31 +0200 Subject: [PATCH] fix some more issues with buffer ending before decisions are finished. --- src/util/order_parser.c | 16 +++++++++++++++- src/util/order_parser.test.c | 12 ++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/util/order_parser.c b/src/util/order_parser.c index ec40f5615..8bf4c7e8d 100644 --- a/src/util/order_parser.c +++ b/src/util/order_parser.c @@ -144,7 +144,21 @@ static enum OP_Status parse_buffer(OP_Parser parser, int isFinal) } else { /* this is not multi-line input yet, so do nothing */ - pos = strpbrk(pos + 1, "\\;\n"); + if (pos[1] == '\0') { + /* end of available input */ + if (isFinal) { + /* input ends on a pointless backslash, kill it */ + pos[0] = '\0'; + pos = NULL; + } + else { + /* backslash is followed by data that we do not know */ + pos = NULL; + } + } + else { + pos = strpbrk(pos + 1, "\\;\n"); + } } break; case ';': diff --git a/src/util/order_parser.test.c b/src/util/order_parser.test.c index a4bc58e97..e9a37fa76 100644 --- a/src/util/order_parser.test.c +++ b/src/util/order_parser.test.c @@ -32,27 +32,39 @@ static void test_parse_orders(CuTest *tc) { OP_SetUserData(parser, lastline); OP_SetOrderHandler(parser, copy_line); CuAssertPtrNotNull(tc, parser); + lastline[0] = 0; CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello World", 11, 1)); CuAssertStrEquals(tc, "Hello World", lastline); OP_ParserReset(parser); + lastline[0] = 0; CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello World\n", 12, 1)); CuAssertStrEquals(tc, "Hello World", lastline); OP_ParserReset(parser); + lastline[0] = 0; CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello\\\n World", 13, 1)); CuAssertStrEquals(tc, "Hello World", lastline); OP_ParserReset(parser); + lastline[0] = 0; CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello;World", 11, 1)); CuAssertStrEquals(tc, "Hello", lastline); OP_ParserReset(parser); + lastline[0] = 0; CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello\\World", 11, 1)); CuAssertStrEquals(tc, "Hello\\World", lastline); OP_ParserReset(parser); + lastline[0] = 0; CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello ", 6, 0)); CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "World", 5, 1)); CuAssertStrEquals(tc, "Hello World", lastline); OP_ParserReset(parser); + lastline[0] = 0; CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello\\World \\", 14, 1)); CuAssertStrEquals(tc, "Hello\\World ", lastline); + OP_ParserReset(parser); + lastline[0] = 0; + CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "Hello \\", 7, 0)); + CuAssertIntEquals(tc, OP_STATUS_OK, OP_Parse(parser, "\nWorld", 6, 1)); + CuAssertStrEquals(tc, "Hello World", lastline); OP_ParserFree(parser); }