From: John Darrington Date: Fri, 12 May 2017 10:25:55 +0000 (+0200) Subject: MEANS: Prevent parser from entering infinite loop. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eff2701d5d282bfc0c1b52bd2af985705b11b307;p=pspp MEANS: Prevent parser from entering infinite loop. Fixes bug #51008 . --- diff --git a/src/language/stats/means.c b/src/language/stats/means.c index debb443676..8fa1ba81cd 100644 --- a/src/language/stats/means.c +++ b/src/language/stats/means.c @@ -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. diff --git a/tests/language/stats/means.at b/tests/language/stats/means.at index 56ab455ba8..0d990f85b1 100644 --- a/tests/language/stats/means.at +++ b/tests/language/stats/means.at @@ -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 + + + +