spvbin-helpers: Properly handle parsing strings with no destination.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 7 Feb 2021 03:52:24 +0000 (19:52 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 7 Feb 2021 03:52:24 +0000 (19:52 -0800)
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

index 138e213957b9b7cfe5819a51bfb8d92f711bf08a..53ea5d4ac4758de4343a7c79d3890d830c0077a2 100644 (file)
@@ -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)