From 8883251bf98f5259c497d6aca1c7e73bb6ef5537 Mon Sep 17 00:00:00 2001 From: Rangi Date: Mon, 20 Jul 2026 00:06:09 -0400 Subject: [PATCH] Avoid UB from `FileStackNodeType(type)` on an invalid `type` --- src/link/object.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/link/object.cpp b/src/link/object.cpp index 5976970f..8dfd7387 100644 --- a/src/link/object.cpp +++ b/src/link/object.cpp @@ -108,9 +108,9 @@ static void readFileStackNode( node.lineNo, file, "%s: Cannot read node #%" PRIu32 "'s line number: %s", fileName, nodeID ); - uint8_t type; - tryGetc(type, file, "%s: Cannot read node #%" PRIu32 "'s type: %s", fileName, nodeID); - switch (type & ~(1 << FSTACKNODE_QUIET_BIT)) { + uint8_t typeAndQuiet; + tryGetc(typeAndQuiet, file, "%s: Cannot read node #%" PRIu32 "'s type: %s", fileName, nodeID); + switch (uint8_t type = typeAndQuiet & ~(1 << FSTACKNODE_QUIET_BIT); type) { case NODE_FILE: case NODE_MACRO: node.type = FileStackNodeType(type); @@ -149,7 +149,7 @@ static void readFileStackNode( fatal("%s: Node #%" PRIu32 " has unknown type 0x%02x", fileName, nodeID, type); } - node.isQuiet = (type & (1 << FSTACKNODE_QUIET_BIT)) != 0; + node.isQuiet = (typeAndQuiet & (1 << FSTACKNODE_QUIET_BIT)) != 0; } // Reads a symbol from a file.