From 2d0c4492b676a6ae889a19530a6cd99ac27b267e Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sun, 10 Dec 2023 01:03:40 -0500 Subject: Fix segfault on invalid section name --- src/ini.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/ini.c b/src/ini.c index e34088e..ffa258d 100644 --- a/src/ini.c +++ b/src/ini.c @@ -289,6 +289,13 @@ struct INIFILE *ini_open(const char *filename) { // Test for section header: [string] if (startswith(line, "[")) { + key_last = NULL; + char *name = substring_between(line, "[]"); + if (!name) { + fprintf(stderr, "error: invalid section syntax, line %zu: '%s'\n", i + 1, line); + return NULL; + } + // Ignore default section because we already have an implicit one if (!strncmp(&line[1], "default", strlen("default"))) { continue; -- cgit