Skip to content

Commit 606c1cf

Browse files
authored
Merge branch 'dreamstalker:master' into master
2 parents a073c45 + de3679f commit 606c1cf

File tree

18 files changed

+130
-36
lines changed

18 files changed

+130
-36
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ jobs:
277277
github.event.action == 'published' &&
278278
startsWith(github.ref, 'refs/tags/')
279279
run: |
280-
7z a -tzip rehlds-bin-${{ env.APP_VERSION }}.zip bin/linux32/ hlsdk/
280+
7z a -tzip rehlds-bin-${{ env.APP_VERSION }}.zip bin/ hlsdk/
281281
7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -aoa rehlds-dbg-${{ env.APP_VERSION }}.7z debug/
282282
283283
- name: Publish artifacts

rehlds/HLTV/Core/src/BSPModel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ byte *BSPModel::LeafPVS(mleaf_t *leaf)
170170

171171
byte *BSPModel::DecompressVis(unsigned char *in)
172172
{
173-
static unsigned char decompressed[MODEL_MAX_PVS];
173+
static unsigned char decompressed[MAX_MAP_LEAFS / 8];
174174
if (in == nullptr) {
175175
return m_novis;
176176
}

rehlds/HLTV/Core/src/BSPModel.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "l_studio.h"
3434
#include "edict.h"
35+
#include "bspfile.h"
3536

3637
// values for model_t's needload
3738
#define NL_PRESENT 0
@@ -87,9 +88,7 @@ class BSPModel: public IBSPModel {
8788

8889
protected:
8990
model_t m_model;
90-
91-
enum { MODEL_MAX_PVS = 1024 };
92-
byte m_novis[MODEL_MAX_PVS];
91+
byte m_novis[MAX_MAP_LEAFS / 8];
9392
byte *m_base;
9493

9594
int m_visframecount;

rehlds/engine/cmodel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@
3131
unsigned char *gPAS;
3232
unsigned char *gPVS;
3333
int gPVSRowBytes;
34-
unsigned char mod_novis[MODEL_MAX_PVS];
34+
unsigned char mod_novis[MAX_MAP_LEAFS / 8];
3535

3636
void Mod_Init(void)
3737
{
3838
SW_Mod_Init();
39-
Q_memset(mod_novis, 255, MODEL_MAX_PVS);
39+
Q_memset(mod_novis, 0xFF, MAX_MAP_LEAFS / 8);
4040
}
4141

4242
unsigned char *Mod_DecompressVis(unsigned char *in, model_t *model)
4343
{
44-
static unsigned char decompressed[MODEL_MAX_PVS];
44+
static unsigned char decompressed[MAX_MAP_LEAFS / 8];
4545

4646
if (in == NULL)
4747
{

rehlds/engine/cmodel.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,10 @@
2929
#pragma once
3030

3131
#include "maintypes.h"
32-
#include "model.h"
33-
34-
// Looks like no more than 8096 visibility leafs per world model
35-
const int MODEL_MAX_PVS = 1024;
3632

3733
extern unsigned char *gPAS;
3834
extern unsigned char *gPVS;
3935
extern int gPVSRowBytes;
40-
extern unsigned char mod_novis[MODEL_MAX_PVS];
4136

4237
void Mod_Init(void);
4338
unsigned char *Mod_DecompressVis(unsigned char *in, model_t *model);

rehlds/engine/common.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,6 +1978,34 @@ NOXREF int COM_ExpandFilename(char *filename)
19781978
return *filename != 0;
19791979
}
19801980

1981+
// small helper function shared by lots of modules
1982+
qboolean COM_IsAbsolutePath(const char *pStr)
1983+
{
1984+
if (strchr(pStr, ':') || pStr[0] == '/' || pStr[0] == '\\')
1985+
return FALSE;
1986+
1987+
return TRUE;
1988+
}
1989+
1990+
qboolean COM_IsValidPath(const char *pszFilename)
1991+
{
1992+
if (!pszFilename)
1993+
return FALSE;
1994+
1995+
if (Q_strlen(pszFilename) <= 0 ||
1996+
Q_strstr(pszFilename, "\\\\") || // to protect network paths
1997+
Q_strstr(pszFilename, ":") || // to protect absolute paths
1998+
Q_strstr(pszFilename, "..") || // to protect relative paths
1999+
Q_strstr(pszFilename, "~") ||
2000+
Q_strstr(pszFilename, "\n") || // CFileSystem_Stdio::FS_fopen doesn't allow this
2001+
Q_strstr(pszFilename, "\r")) // CFileSystem_Stdio::FS_fopen doesn't allow this
2002+
{
2003+
return FALSE;
2004+
}
2005+
2006+
return TRUE;
2007+
}
2008+
19812009
int EXT_FUNC COM_FileSize(const char *filename)
19822010
{
19832011
FileHandle_t fp;

rehlds/engine/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ void COM_CreatePath(char *path);
187187
NOXREF void COM_CopyFile(char *netpath, char *cachepath);
188188
NOXREF int COM_ExpandFilename(char *filename);
189189
int COM_FileSize(const char *filename);
190+
qboolean COM_IsAbsolutePath(const char *pStr);
191+
qboolean COM_IsValidPath(const char *pszFilename);
190192
unsigned char *COM_LoadFile(const char *path, int usehunk, int *pLength);
191193
void COM_FreeFile(void *buffer);
192194
void COM_CopyFileChunk(FileHandle_t dst, FileHandle_t src, int nSize);

rehlds/engine/host_cmd.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,19 @@ void Host_Motd_f(void)
205205
char *next;
206206

207207
pFileList = motdfile.string;
208-
if (*pFileList == '/' || Q_strstr(pFileList, ":") || Q_strstr(pFileList, "..") || Q_strstr(pFileList, "\\"))
208+
if (!COM_IsValidPath(pFileList) || COM_IsAbsolutePath(pFileList))
209209
{
210210
Con_Printf("Unable to open %s (contains illegal characters)\n", pFileList);
211211
return;
212212
}
213+
214+
const char *pchExtension = COM_FileExtension(pFileList);
215+
if (Q_stricmp(pchExtension, "txt") != 0)
216+
{
217+
Con_Printf("Invalid motdfile name %s (wrong file extension, must be .txt)\n", pFileList);
218+
return;
219+
}
220+
213221
pFile = FS_Open(pFileList, "rb");
214222
if (!pFile)
215223
{

rehlds/engine/pr_cmds.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,9 @@ int EXT_FUNC PF_precache_model_I_internal(const char *s)
14471447
{
14481448
for (int i = 0; i < MAX_MODELS; i++)
14491449
{
1450+
if (!g_psv.model_precache[i])
1451+
continue;
1452+
14501453
// use case-sensitive names to increase performance
14511454
#ifdef REHLDS_FIXES
14521455
if (!Q_strcmp(g_psv.model_precache[i], s))
@@ -1545,7 +1548,7 @@ int EXT_FUNC PF_precache_generic_I_internal(const char *s)
15451548
{
15461549
for (int i = 0; i < MAX_GENERIC; i++)
15471550
{
1548-
if (!Q_stricmp(g_psv.generic_precache[i], s))
1551+
if (g_psv.generic_precache[i] && !Q_stricmp(g_psv.generic_precache[i], s))
15491552
return i;
15501553
}
15511554
Host_Error("%s: '%s' Precache can only be done in spawn functions", __func__, s);

rehlds/engine/r_studio.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,15 @@ void EXT_FUNC AnimationAutomove(const edict_t *pEdict, float flTime)
881881
void EXT_FUNC GetBonePosition(const edict_t *pEdict, int iBone, float *rgflOrigin, float *rgflAngles)
882882
{
883883
pstudiohdr = (studiohdr_t *)Mod_Extradata(g_psv.models[pEdict->v.modelindex]);
884+
885+
#ifdef REHLDS_FIXES
886+
if (!pstudiohdr)
887+
return;
888+
889+
if (iBone < 0 || iBone >= pstudiohdr->numbones)
890+
return; // invalid bone
891+
#endif
892+
884893
g_pSvBlendingAPI->SV_StudioSetupBones(
885894
g_psv.models[pEdict->v.modelindex],
886895
pEdict->v.frame,
@@ -906,14 +915,23 @@ void EXT_FUNC GetAttachment(const edict_t *pEdict, int iAttachment, float *rgflO
906915
mstudioattachment_t *pattachment;
907916
vec3_t angles;
908917

909-
angles[0] = -pEdict->v.angles[0];
910-
angles[1] = pEdict->v.angles[1];
911-
angles[2] = pEdict->v.angles[2];
912-
913918
pstudiohdr = (studiohdr_t *)Mod_Extradata(g_psv.models[pEdict->v.modelindex]);
919+
920+
#ifdef REHLDS_FIXES
921+
if (!pstudiohdr)
922+
return;
923+
924+
if (iAttachment < 0 || iAttachment >= pstudiohdr->numattachments)
925+
return; // invalid attachment
926+
#endif
927+
914928
pattachment = (mstudioattachment_t *)((char *)pstudiohdr + pstudiohdr->attachmentindex);
915929
pattachment += iAttachment;
916930

931+
angles[0] = -pEdict->v.angles[0];
932+
angles[1] = pEdict->v.angles[1];
933+
angles[2] = pEdict->v.angles[2];
934+
917935
g_pSvBlendingAPI->SV_StudioSetupBones(
918936
g_psv.models[pEdict->v.modelindex],
919937
pEdict->v.frame,

0 commit comments

Comments
 (0)