From 09c9395ff8b23b5c7beb431d0228d5e2129d56d6 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Sun, 13 Oct 2019 15:17:34 +0200 Subject: [PATCH] Fix NULL deref when fetching an unknown symbol in RPN expressions was being overwritten with the result, so was meaningless. Using a temporary instead is better. --- src/link/patch.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/link/patch.c b/src/link/patch.c index 255a7f7a..ab76da0a 100644 --- a/src/link/patch.c +++ b/src/link/patch.c @@ -192,11 +192,13 @@ static int32_t computeRPNExpr(struct Patch const *patch, /* If the symbol is defined elsewhere... */ if (symbol->type == SYMTYPE_IMPORT) { - symbol = sym_GetSymbol(symbol->name); - if (!symbol) + struct Symbol const *symbolDefinition = + sym_GetSymbol(symbol->name); + if (!symbolDefinition) errx(1, "%s(%d): Unknown symbol \"%s\"", patch->fileName, patch->lineNo, symbol->name); + symbol = symbolDefinition; } value = symbol->section->bank; @@ -250,11 +252,13 @@ static int32_t computeRPNExpr(struct Patch const *patch, /* If the symbol is defined elsewhere... */ if (symbol->type == SYMTYPE_IMPORT) { - symbol = sym_GetSymbol(symbol->name); - if (!symbol) + struct Symbol const *symbolDefinition = + sym_GetSymbol(symbol->name); + if (!symbolDefinition) errx(1, "%s(%d): Unknown symbol \"%s\"", patch->fileName, patch->lineNo, symbol->name); + symbol = symbolDefinition; } if (!strcmp(symbol->name, "@")) {