shithub: riscv

Download patch

ref: 140ca8fb119f8c6b57f53e7b599e27a2df163de4
parent: 526f63106b232665a8288ebf2d79c8ad659a2e37
author: qwx <qwx@sciops.net>
date: Wed Sep 13 01:22:32 EDT 2023

games/doom: don't crash on invalid music selection with idmus cheat

see also: https://doomwiki.org/wiki/IDMUS_requests_invalid_music

--- a/sys/src/games/doom/st_stuff.c
+++ b/sys/src/games/doom/st_stuff.c
@@ -600,21 +600,21 @@
 	
 	if (gamemode == commercial)
 	{
-	  musnum = mus_runnin + (buf[0]-'0')*10 + buf[1]-'0' - 1;
+	  musnum = (buf[0]-'0')*10 + buf[1]-'0' - 1;
 	  
-	  if (((buf[0]-'0')*10 + buf[1]-'0') > 35)
+	  if (musnum < 0 || musnum > 34)
 	    plyr->message = STSTR_NOMUS;
 	  else
-	    S_ChangeMusic(musnum, 1);
+	    S_ChangeMusic(mus_runnin + musnum, 1);
 	}
 	else
 	{
-	  musnum = mus_e1m1 + (buf[0]-'1')*9 + (buf[1]-'1');
+	  musnum = (buf[0]-'1')*9 + buf[1]-'1';
 	  
-	  if (((buf[0]-'1')*9 + buf[1]-'1') > 31)
+	  if (musnum < 0 || musnum > 31)
 	    plyr->message = STSTR_NOMUS;
 	  else
-	    S_ChangeMusic(musnum, 1);
+	    S_ChangeMusic(mus_e1m1 + musnum, 1);
 	}
       }
       // Simplified, accepting both "noclip" and "idspispopd".