From dfe0e72c0e8697025718276d28c7c07f5a769dc5 Mon Sep 17 00:00:00 2001
From: Lactozilla <jp6781615@gmail.com>
Date: Sun, 13 Aug 2023 22:01:34 -0300
Subject: [PATCH] Ensure teamscores[TEAM_NONE] can't be written to or read

---
 src/lua_infolib.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/lua_infolib.c b/src/lua_infolib.c
index 0e5b75d141..8c8de99f48 100644
--- a/src/lua_infolib.c
+++ b/src/lua_infolib.c
@@ -2434,27 +2434,27 @@ static int teamlist_len(lua_State *L)
 static int teamscores_get(lua_State *L)
 {
 	UINT32 *scoreslist = *((UINT32 **)luaL_checkudata(L, 1, META_TEAMSCORES));
-	int i = luaL_checkinteger(L, 2);
-	if (i < 0 || i >= numteams)
-		return luaL_error(L, "array index %d out of range (0 - %d)", i, numteams - 1);
-	lua_pushinteger(L, scoreslist[i]);
+	int team = luaL_checkinteger(L, 2);
+	if (team <= 0 || team >= numteams)
+		return luaL_error(L, "team index %d out of range (1 - %d)", team, max(0, (int)numteams - 1));
+	lua_pushinteger(L, scoreslist[team]);
 	return 1;
 }
 
 static int teamscores_set(lua_State *L)
 {
 	UINT32 *scoreslist = *((UINT32 **)luaL_checkudata(L, 1, META_TEAMSCORES));
-	int i = luaL_checkinteger(L, 2);
+	int team = luaL_checkinteger(L, 2);
 	UINT32 score = (UINT32)luaL_checkinteger(L, 3);
-	if (i < 0 || i >= numteams)
-		return luaL_error(L, "array index %d out of range (0 - %d)", i, numteams - 1);
-	scoreslist[i] = score;
+	if (team <= 0 || team >= numteams)
+		return luaL_error(L, "array index %d out of range (1 - %d)", team, max(0, (int)numteams - 1));
+	scoreslist[team] = score;
 	return 0;
 }
 
 static int teamscores_len(lua_State *L)
 {
-	lua_pushinteger(L, numteams);
+	lua_pushinteger(L, max(0, numteams - 1));
 	return 1;
 }
 
-- 
GitLab