From 28d8301b5fd871a216c7cbea3d7f18609f9ce408 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Fri, 28 Jun 2024 15:05:28 +0200 Subject: [PATCH] Prevent crash upon buggy user input --- src/spicelib/parser/inpptree.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/spicelib/parser/inpptree.c b/src/spicelib/parser/inpptree.c index 2301dd979..66c88768b 100644 --- a/src/spicelib/parser/inpptree.c +++ b/src/spicelib/parser/inpptree.c @@ -753,7 +753,7 @@ static INPparseNode *PTdifferentiate(INPparseNode * p, int varnum) break; default: - fprintf(stderr, "Internal error: bad node type %d\n", p->type); + fprintf(stderr, "Error: bad node type %d\n", p->type); newp = NULL; break; } @@ -778,6 +778,10 @@ static INPparseNode *mkb(int type, INPparseNode * left, INPparseNode *p; int i; + if (!right || !left) { + return (NULL); + } + if ((right->type == PT_CONSTANT) && (left->type == PT_CONSTANT)) { double value; switch (type) { @@ -890,6 +894,9 @@ static INPparseNode *mkf(int type, INPparseNode * arg) INPparseNode *p; int i; + if (!arg) + return NULL; + for (i = 0; i < NUM_FUNCS; i++) if (funcs[i].number == type) break;