From d90a738745006b2696994bec344c160fca1f755b Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sat, 20 Jun 2020 07:17:06 +0200 Subject: [PATCH] Fix crash when cleaning up after parsing bad MODIFY VARIABLES. Reported by: Andrea Fioraldi Fixes Bug: #58590 --- src/language/dictionary/modify-variables.c | 5 +++-- tests/language/dictionary/modify-variables.at | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/language/dictionary/modify-variables.c b/src/language/dictionary/modify-variables.c index 58853abd36..ab73bbb899 100644 --- a/src/language/dictionary/modify-variables.c +++ b/src/language/dictionary/modify-variables.c @@ -360,8 +360,9 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds) done: free (vm.reorder_vars); free (vm.rename_vars); - for (size_t i = 0; i < vm.n_rename; i++) - free (vm.new_names[i]); + if (vm.new_names) + for (size_t i = 0; i < vm.n_rename; i++) + free (vm.new_names[i]); free (vm.new_names); free (vm.drop_vars); return ret_code; diff --git a/tests/language/dictionary/modify-variables.at b/tests/language/dictionary/modify-variables.at index 6fcd6b840a..f101ba7211 100644 --- a/tests/language/dictionary/modify-variables.at +++ b/tests/language/dictionary/modify-variables.at @@ -1,5 +1,5 @@ dnl PSPP - a program for statistical analysis. -dnl Copyright (C) 2017 Free Software Foundation, Inc. +dnl Copyright (C) 2017, 2020 Free Software Foundation, Inc. dnl dnl This program is free software: you can redistribute it and/or modify dnl it under the terms of the GNU General Public License as published by @@ -237,3 +237,17 @@ modify-variables.sps:16: error: MODIFY VARS: MODIFY VARS may not be used to dele modify-variables.sps:17: error: Stopping syntax file processing here to avoid a cascade of dependent command failures. ]) AT_CLEANUP + +AT_SETUP([MODIFY VARS crash]) +AT_DATA([modify-variables.sps], [dnl +DATA LIST notable LIST /a b c (F2.0). +BEGIN DATA. +1 2 3 +END DATA. + +MODIFY VARS /RENAME (a 4 c = one two three). +]) + +AT_CHECK([pspp -O format=csv modify-variables.sps], [1], [ignore]) + +AT_CLEANUP -- 2.30.2