From b42ed9c6185362e6153597160c494631938cfb5c Mon Sep 17 00:00:00 2001 From: CK Tan Date: Sat, 18 Nov 2017 11:57:45 -0800 Subject: [PATCH] libtomlc99: fix segfaulting test Pulled from cktan/tomlc99@01ecb88d1. This fixes cktan/tomlc99#3: bad input file causes segfault. --- src/libtomlc99/toml.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libtomlc99/toml.c b/src/libtomlc99/toml.c index 0e00a83affca..669d6d218c77 100644 --- a/src/libtomlc99/toml.c +++ b/src/libtomlc99/toml.c @@ -1140,6 +1140,10 @@ static void parse_select(context_t* ctx) /* [[x.y.z]] -> create z = [] in x.y */ toml_array_t* arr = create_keyarray_in_table(ctx, ctx->curtab, z, 1 /*skip_if_exist*/); + if (!arr) { + e_syntax_error(ctx, z.lineno, "key exists"); + return; + } if (arr->kind == 0) arr->kind = 't'; if (arr->kind != 't') { e_syntax_error(ctx, z.lineno, "array mismatch");