From caa0a7f4a846062ec8f00b095eceebb32a9fdeea Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Wed, 1 Jan 2025 15:05:14 +0100 Subject: [PATCH] Fix a crash due to buggy user input. Improve error message. Reported in https://gitlab.com/kicad/code/kicad/-/issues/19439#note_2277932762 --- src/frontend/parse.c | 6 ++++++ src/frontend/postcoms.c | 1 + 2 files changed, 7 insertions(+) diff --git a/src/frontend/parse.c b/src/frontend/parse.c index ebe22d309..4c31a3fbe 100644 --- a/src/frontend/parse.c +++ b/src/frontend/parse.c @@ -117,6 +117,12 @@ struct pnode* ft_getpnames_quotes(wordlist* wl, bool check) tmpstr += 2; /* get the complete zzz of v(zzz) */ char* tpartoken = tmpstr2 = gettok_char(&tmpstr, ')', FALSE, FALSE); + /* Bail out in case of missing closing paren */ + if (!tpartoken) { + fprintf(stderr, "Error: Missing ')' in token %s\n", sz); + fprintf(stderr, " Cannot parse the token!\n"); + return NULL; + } /* check if this is v(zzz) or v(xx,yy) */ char* partoken1 = gettok_char(&tpartoken, ',', FALSE, FALSE); sadd(&ds1, "v("); diff --git a/src/frontend/postcoms.c b/src/frontend/postcoms.c index 1e6e51d71..a19160ae9 100644 --- a/src/frontend/postcoms.c +++ b/src/frontend/postcoms.c @@ -469,6 +469,7 @@ com_write(wordlist *wl) names = ft_getpnames_quotes(&all, TRUE); if (names == NULL) { + fprintf(stderr, "Error during 'write': no writable vector found.\n"); return; }