From 63733a45b789cd12bacafcea52d28704adfeb5e5 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sat, 20 Jun 2020 07:17:06 +0200 Subject: [PATCH] Don't crash when parsing bad MATRIX DATA commands. Reported by: Andrea Fioraldi Fixes bug: #58596 --- src/language/data-io/matrix-data.c | 8 ++++++-- tests/language/data-io/matrix-data.at | 28 ++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/language/data-io/matrix-data.c b/src/language/data-io/matrix-data.c index 7676bb1de0..8ce325154b 100644 --- a/src/language/data-io/matrix-data.c +++ b/src/language/data-io/matrix-data.c @@ -220,6 +220,9 @@ preprocess (struct casereader *casereader0, const struct dictionary *dict, void casereader_destroy (pass0); free (prev_values); + if (!matrices) + goto error; + /* Now make a second pass to fill in the other triangle from our temporary matrix */ const int idx = var_get_dict_index (mformat->varname); @@ -375,8 +378,9 @@ error: if (prev_case) case_unref (prev_case); - for (i = 0 ; i < n_splits; ++i) - free (matrices[i]); + if (matrices) + for (i = 0 ; i < n_splits; ++i) + free (matrices[i]); free (matrices); casereader_destroy (casereader0); casewriter_destroy (writer); diff --git a/tests/language/data-io/matrix-data.at b/tests/language/data-io/matrix-data.at index f389ade64d..8f503f62f2 100644 --- a/tests/language/data-io/matrix-data.at +++ b/tests/language/data-io/matrix-data.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 @@ -482,3 +482,29 @@ corr,var04,7.0000,5.0000,4.0000,1.0000 ]) AT_CLEANUP + + + +dnl A "no-crash" test. This was observed to cause problems. +dnl See bug #58596 +AT_SETUP([Matrix data crash]) + +AT_DATA([matrix-data.pspp], [dnl +begin data +corr 31 + +matrix data + var1 +begin data + corr 1.00 +end data . + +matrix data + variables = roxtype_ var01 + /format = upper nodiagonal. +begin data +]) + +AT_CHECK([pspp -O format=csv matrix-data.pspp], [1], [ignore]) + +AT_CLEANUP -- 2.30.2