From 19e1d400e4c5b196d400154c2d84d0aa91d84f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Sat, 5 Oct 2024 23:03:05 -0300 Subject: [PATCH] Add bounds checking to GetMidTexturePosition, add assert to P_GetMidTexturePosition --- src/playsim/p_3dmidtex.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/playsim/p_3dmidtex.cpp b/src/playsim/p_3dmidtex.cpp index 0e2d7e10d..86937b53c 100644 --- a/src/playsim/p_3dmidtex.cpp +++ b/src/playsim/p_3dmidtex.cpp @@ -229,6 +229,8 @@ bool P_GetMidTexturePosition(const line_t *line, int sideno, double *ptextop, do { if (line->sidedef[0]==NULL || line->sidedef[1]==NULL) return false; + assert(sideno >= 0 && sideno <= 1); + side_t *side = line->sidedef[sideno]; FTextureID texnum = side->GetTexture(side_t::mid); if (!texnum.isValid()) return false; @@ -266,6 +268,9 @@ DEFINE_ACTION_FUNCTION(_Line, GetMidTexturePosition) double top = 0.0; double bottom = 0.0; + if(side < 0) ThrowAbortException(X_ARRAY_OUT_OF_BOUNDS, "side is negative"); + else if(side > 1) ThrowAbortException(X_ARRAY_OUT_OF_BOUNDS, "side is greater than one"); + bool res = P_GetMidTexturePosition(self,side,&top,&bottom); if (numret > 2) ret[2].SetFloat(bottom); if (numret > 1) ret[1].SetFloat(top);