From 1f352ca17a0797251e19e1e91f4f4d2d4c4cf464 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 25 Mar 2016 14:16:03 +0100 Subject: [PATCH] Fix crash in DATA LIST when RECORDS and/or SKIP is negative Found by zzuf --- src/language/data-io/data-list.c | 17 +++++++++++++-- tests/language/data-io/data-list.at | 33 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/language/data-io/data-list.c b/src/language/data-io/data-list.c index 90d060eaab..31f51bca3c 100644 --- a/src/language/data-io/data-list.c +++ b/src/language/data-io/data-list.c @@ -122,7 +122,14 @@ cmd_data_list (struct lexer *lexer, struct dataset *ds) lex_match (lexer, T_LPAREN); if (!lex_force_int (lexer)) goto error; - data_parser_set_records (parser, lex_integer (lexer)); + + int records = lex_integer (lexer); + if (records < 0) + { + msg (SE, _("The %s value must be nonnegative."), "RECORDS"); + goto error; + } + data_parser_set_records (parser, records); lex_get (lexer); lex_match (lexer, T_RPAREN); } @@ -131,7 +138,13 @@ cmd_data_list (struct lexer *lexer, struct dataset *ds) lex_match (lexer, T_EQUALS); if (!lex_force_int (lexer)) goto error; - data_parser_set_skip (parser, lex_integer (lexer)); + int skip = lex_integer (lexer); + if (skip < 0) + { + msg (SE, _("The %s value must be nonnegative."), "SKIP"); + goto error; + } + data_parser_set_skip (parser, skip); lex_get (lexer); } else if (lex_match_id (lexer, "END")) diff --git a/tests/language/data-io/data-list.at b/tests/language/data-io/data-list.at index b758411687..d154fd97fe 100644 --- a/tests/language/data-io/data-list.at +++ b/tests/language/data-io/data-list.at @@ -384,3 +384,36 @@ Case Number,A ]) AT_CLEANUP + + +AT_SETUP([DATA LIST - Negative SKIP]) +AT_DATA([data-list.sps], [dnl +DATA LIST LIST FILE='f.in' NOTABLE SKIP=-1 /a b c d. + +EXECUTE. +]) + +AT_CHECK([pspp -O format=csv data-list.sps], [1], [dnl +data-list.sps:1: error: DATA LIST: The SKIP value must be nonnegative. + +data-list.sps:3: error: Stopping syntax file processing here to avoid a cascade of dependent command failures. +]) + +AT_CLEANUP + + +AT_SETUP([DATA LIST - Negative RECORDS]) +AT_DATA([data-list.sps], [dnl +DATA LIST LIST FILE='f.in' NOTABLE RECORDS=-1 /a b c d. + +EXECUTE. +]) + +AT_CHECK([pspp -O format=csv data-list.sps], [1], [dnl +data-list.sps:1: error: DATA LIST: The RECORDS value must be nonnegative. + +data-list.sps:3: error: Stopping syntax file processing here to avoid a cascade of dependent command failures. +]) + +AT_CLEANUP + -- 2.30.2