From e604884bd74bd10cef3efac494c739bdf043eb68 Mon Sep 17 00:00:00 2001 From: "H. Utku Maden" Date: Thu, 12 Dec 2024 18:57:26 +0300 Subject: [PATCH] Fixed gr_glinfo crash when there are way too many extensions present. --- src/hardware/hw_main.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 409667027..57408998b 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5702,7 +5702,25 @@ static void COM_HWR_glinfo(void) CONS_Printf("%u GL extensions present.\n", gl_num_extensions); if (list_extensions) { - CONS_Printf("%s\n", gl_extensions); + // We need this strtok loop because we cannot write the extensions list directly + // to the output buffer, because it will overflow the output buffer of CONS_Printf + // if the GPU is super new and supports a bajillion extensions - xyzzy + + char *copy = strdup((const char*)gl_extensions); + char *ext = strtok(copy, " "); + + if (copy == NULL) + { + CONS_Printf("Ran out of memory listing extensions?!?!"); + return; + } + + do + { + CONS_Printf(" - %s\n", ext); + } while ((ext = strtok(NULL, " ")) != NULL); + + free(copy); } else {