Fix crash in DATA LIST when RECORDS and/or SKIP is negative
authorJohn Darrington <john@darrington.wattle.id.au>
Fri, 25 Mar 2016 13:16:03 +0000 (14:16 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Fri, 25 Mar 2016 13:16:03 +0000 (14:16 +0100)
Found by zzuf

src/language/data-io/data-list.c
tests/language/data-io/data-list.at

index 90d060eaab66721a8462fcb81baa351494177441..31f51bca3c303def3f4b9c392a8e3bb58cf4dd47 100644 (file)
@@ -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"))
index b7584116873efcf9a19c25972883819bbcf6a82c..d154fd97fe0af228b806be1a6f7303fc2d9362ed 100644 (file)
@@ -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
+