MEANS: Prevent parser from entering infinite loop.
authorJohn Darrington <john@darrington.wattle.id.au>
Fri, 12 May 2017 10:25:55 +0000 (12:25 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Fri, 12 May 2017 10:39:54 +0000 (12:39 +0200)
Fixes bug #51008
.

src/language/stats/means.c
tests/language/stats/means.at

index debb4436764263bfa1c9147600a5bc388d1051e9..8fa1ba81cd51f7326e228c6a2d2047a5804e74a1 100644 (file)
@@ -511,23 +511,19 @@ parse_means_table_syntax (struct lexer *lexer, const struct means *cmd, struct m
     return false;
 
   /* Factor variable (s) */
-  while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH)
+  while (lex_match (lexer, T_BY))
     {
-      if (lex_match (lexer, T_BY))
-       {
-         table->n_layers++;
-          table->layers =
-           pool_realloc (cmd->pool, table->layers,
-                         sizeof (*table->layers) * table->n_layers);
-
-         if (!parse_variables_const_pool
-              (lexer, cmd->pool, cmd->dict,
-               &table->layers[table->n_layers - 1].factor_vars,
-               &table->layers[table->n_layers - 1].n_factor_vars,
-               PV_NO_DUPLICATE))
-           return false;
-
-       }
+      table->n_layers++;
+      table->layers =
+       pool_realloc (cmd->pool, table->layers,
+                     sizeof (*table->layers) * table->n_layers);
+
+      if (!parse_variables_const_pool
+         (lexer, cmd->pool, cmd->dict,
+          &table->layers[table->n_layers - 1].factor_vars,
+          &table->layers[table->n_layers - 1].n_factor_vars,
+          PV_NO_DUPLICATE))
+       return false;
     }
 
   /* There is always at least one layer.
index 56ab455ba87734b5638a35f3cf7caba626f52fa5..0d990f85b125deaf82326b29e75366b8d6b64dd9 100644 (file)
@@ -570,4 +570,26 @@ MEANS TABLES =  outcome
 
 AT_CHECK([pspp -O format=csv means-bad.sps], [1], [ignore])
 
-AT_CLEANUP
\ No newline at end of file
+AT_CLEANUP
+
+
+
+AT_SETUP([MEANS parser bug])
+
+dnl This bug caused an infinite loop
+AT_DATA([means-bad.sps], [dnl
+DATA LIST notable LIST /a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 fylo *.
+begin data.
+1 2 3 4 5 6 7 8 9 0 11
+end data.
+
+MEANS TABLES = a1 a2 a3 a4 a5 a6 a7 a8 a9 a10a BY fylo.
+])
+
+AT_CHECK([pspp -O format=csv means-bad.sps], [1], [ignore])
+
+AT_CLEANUP
+
+
+
+