Skip to content

Commit

Permalink
Don't add an invalid decal into custom.hpk, otherwise clients may cra…
Browse files Browse the repository at this point in the history
…sh because they have no safe-checks WAD3 MIP-Header.

Related #755 (Only fixes server-side)
Fixes #757
  • Loading branch information
s1lentq committed Apr 6, 2020
1 parent 07539e2 commit 7513e71
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion rehlds/engine/com_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ qboolean COM_CreateCustomization(customization_t *pListHead, resource_t *pResour
if ((pCust->resource.ucFlags & RES_CUSTOM) && pCust->resource.type == t_decal)
{
pCust->resource.playernum = playernumber;
if (!CustomDecal_Validate(pCust->pBuffer, pResource->nDownloadSize))

if (!(flags & FCUST_VALIDATED) && // Don't validate twice
!CustomDecal_Validate(pCust->pBuffer, pResource->nDownloadSize))
{
bError = TRUE;
goto CustomizationError;
Expand Down
15 changes: 14 additions & 1 deletion rehlds/engine/sv_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3539,6 +3539,18 @@ void SV_ProcessFile(client_t *cl, char *filename)
return;
}

int iCustomFlags = 0;

#ifdef REHLDS_FIXES
if (!CustomDecal_Validate(cl->netchan.tempbuffer, cl->netchan.tempbuffersize))
{
Con_Printf("Invalid custom decal from %s\n", cl->name);
return;
}

iCustomFlags |= FCUST_VALIDATED;
#endif

HPAK_AddLump(TRUE, "custom.hpk", resource, cl->netchan.tempbuffer, NULL);
resource->ucFlags &= ~RES_WASMISSING;
SV_MoveToOnHandList(resource);
Expand All @@ -3552,7 +3564,8 @@ void SV_ProcessFile(client_t *cl, char *filename)
pList = pList->pNext;
}

if (!COM_CreateCustomization(&cl->customdata, resource, -1, (FCUST_FROMHPAK | FCUST_WIPEDATA | RES_CUSTOM), NULL, NULL))
iCustomFlags |= (FCUST_FROMHPAK | FCUST_WIPEDATA | RES_CUSTOM);
if (!COM_CreateCustomization(&cl->customdata, resource, -1, iCustomFlags, NULL, NULL))
Con_Printf("Error parsing custom decal from %s\n", cl->name);
}

Expand Down
1 change: 1 addition & 0 deletions rehlds/public/rehlds/custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,4 @@ typedef struct customization_s
#define FCUST_FROMHPAK ( 1<<0 )
#define FCUST_WIPEDATA ( 1<<1 )
#define FCUST_IGNOREINIT ( 1<<2 )
#define FCUST_VALIDATED ( 1<<3 )

0 comments on commit 7513e71

Please sign in to comment.