From 78a43b3fd07c601dea27f0568727f515d39a2153 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 6 Feb 2021 19:52:24 -0800 Subject: [PATCH] spvbin-helpers: Properly handle parsing strings with no destination. binary-parser-generator will pass a null pointer to spvbin_parse_string() or spvbin_parse_bestring() for a string that should be parsed but not stored. In such a case, the implementation would dereference a null pointer. This fixes the problem. This is only a theoretical problem because the grammars PSPP uses now always store the strings that they parse. Found by cppcheck. Reported by John Darrington. --- src/output/spv/spvbin-helpers.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/output/spv/spvbin-helpers.c b/src/output/spv/spvbin-helpers.c index 138e213957..53ea5d4ac4 100644 --- a/src/output/spv/spvbin-helpers.c +++ b/src/output/spv/spvbin-helpers.c @@ -180,7 +180,8 @@ spvbin_parse_string__ (struct spvbin_input *input, uint32_t (*raw_to_native32) (uint32_t), char **p) { - *p = NULL; + if (p) + *p = NULL; uint32_t length; if (input->size - input->ofs < sizeof length) -- 2.30.2