From 1cf2c568c9a8d3a515254036916219d1b12de4d0 Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周二, 13 10月 2015 00:49:16 +0800 Subject: [PATCH] Resolve #57: SCPI_ExprChannelListEntry() crashes with whitespaces --- libscpi/src/expression.c | 6 ++++++ libscpi/test/test_parser.c | 3 +++ 2 files changed, 9 insertions(+), 0 deletions(-) diff --git a/libscpi/src/expression.c b/libscpi/src/expression.c index 308a953..1b8cb2e 100644 --- a/libscpi/src/expression.c +++ b/libscpi/src/expression.c @@ -303,5 +303,11 @@ if (res == SCPI_EXPR_ERROR) { SCPI_ErrorPush(context, SCPI_ERROR_EXPRESSION_PARSING_ERROR); } + if (res == SCPI_EXPR_NO_MORE) { + if (!scpiLex_IsEos(&lex)) { + res = SCPI_EXPR_ERROR; + SCPI_ErrorPush(context, SCPI_ERROR_EXPRESSION_PARSING_ERROR); + } + } return res; } diff --git a/libscpi/test/test_parser.c b/libscpi/test/test_parser.c index f810699..2602bd5 100644 --- a/libscpi/test/test_parser.c +++ b/libscpi/test/test_parser.c @@ -760,6 +760,9 @@ TEST_ChannelList("(@1,2!5:3!6!7)", 0, 2, FALSE, 1, (1), (0), SCPI_EXPR_OK, 0); TEST_ChannelList("(@1,2!5:3!6!7)", 1, 2, FALSE, 0, (0), (0), SCPI_EXPR_ERROR, SCPI_ERROR_EXPRESSION_PARSING_ERROR); TEST_ChannelList("(@1,2!5:3!6!7)", 2, 2, FALSE, 0, (0), (0), SCPI_EXPR_ERROR, SCPI_ERROR_EXPRESSION_PARSING_ERROR); + + TEST_ChannelList("(@1, 2)", 0, 1, FALSE, 1, (1), (0), SCPI_EXPR_OK, 0); + TEST_ChannelList("(@1, 2)", 1, 1, FALSE, 0, (0), (0), SCPI_EXPR_ERROR, SCPI_ERROR_EXPRESSION_PARSING_ERROR); } int main() { -- Gitblit v1.9.1