From 021990b8e0c3c05684b3b46595741a146367c0a4 Mon Sep 17 00:00:00 2001 From: dbrotz <43593771+dbrotz@users.noreply.github.com> Date: Sun, 5 May 2019 20:21:55 -0700 Subject: [PATCH] Properly check if a symbol's full name is too long --- src/asm/symbol.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/asm/symbol.c b/src/asm/symbol.c index cdc47b57..1eb929e4 100644 --- a/src/asm/symbol.c +++ b/src/asm/symbol.c @@ -154,12 +154,14 @@ struct sSymbol *createsymbol(char *s) * Creates the full name of a local symbol in a given scope, by prepending * the name with the parent symbol's name. */ -static size_t fullSymbolName(char *output, size_t outputSize, char *localName, - const struct sSymbol *scope) +static void fullSymbolName(char *output, size_t outputSize, char *localName, + const struct sSymbol *scope) { const struct sSymbol *parent = scope->pScope ? scope->pScope : scope; + int n = snprintf(output, outputSize, "%s%s", parent->tzName, localName); - return snprintf(output, outputSize, "%s%s", parent->tzName, localName); + if (n >= (int)outputSize) + fatalerror("Symbol too long"); } /* @@ -561,9 +563,6 @@ void sym_AddSet(char *tzSym, int32_t value) void sym_AddLocalReloc(char *tzSym) { if (pScope) { - if (strlen(tzSym) + strlen(pScope->tzName) > MAXSYMLEN) - fatalerror("Symbol too long"); - char fullname[MAXSYMLEN + 1]; fullSymbolName(fullname, sizeof(fullname), tzSym, pScope);