From 9a2fd53f1da0cd36176a53362b6257c3129c3685 Mon Sep 17 00:00:00 2001 From: Kevin Caccamo Date: Sun, 15 Jun 2025 17:23:48 -0400 Subject: [PATCH] Remove dereferences of comment + 1 If a line ends with a single slash, then you'll get an invalid read --- src/gamedata/keysections.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gamedata/keysections.cpp b/src/gamedata/keysections.cpp index bdb103a74..ebb1efd28 100644 --- a/src/gamedata/keysections.cpp +++ b/src/gamedata/keysections.cpp @@ -197,19 +197,22 @@ void D_LoadWadSettings () // Comments begin with // char *stop = &command[linePos]; char *comment = &command[0]; + char prevChar = 0; bool inQuote = false; while (comment < stop) { - // if (*comment != '\\' && *(comment + 1) == '\"') + // if (prevChar != '\\' && *comment == '\"') if (*comment == '\"') { inQuote = !inQuote; } - else if (!inQuote && *comment == '/' && *(comment + 1) == '/') + else if (!inQuote && prevChar == '/' && *comment == '/') { + comment--; // 'comment' is on the second slash break; } + prevChar = *comment; comment++; } // 'comment' will either be the end of the string, or the starting