Skip to content

Fix multiple memory-safety and out-of-bounds vulnerabilities - #1209

Open
Pokimoshka wants to merge 1 commit into
rehlds:masterfrom
Pokimoshka:pr/security-fixes
Open

Pokimoshka wants to merge 1 commit into
rehlds:masterfrom
Pokimoshka:pr/security-fixes

Conversation

@Pokimoshka

Copy link
Copy Markdown
Contributor

This PR hardens the engine, filesystem and HLTV against malformed network packets, BSP/WAD/MDL model files and demo files. It is a collection of bounds/validation fixes found during a security audit.

Engine

  • model.cpp: validate every BSP lump offset/size against the actual file size, and add planenum/texinfo/children/marksurface/visofs bounds checks in Mod_LoadFaces/Mod_LoadNodes/Mod_LoadLeafs.
  • l_studio.cpp: validate the .mdl header (length/numtextures/texture indices) and per-texture sizes against the real file size (prevents heap overflow via height * width and OOB memcpy).
  • wad.cpp: validate the WAD header and lump table against the file size.
  • delta.cpp: bound DT_STRING writes to the destination structure.
  • hashpak.cpp: validate nFileLength against MAX_FILE_SIZE; fix the MD5 being computed over the wrong file handle.
  • host_cmd.cpp: validate save-game header fields and lightstyle indices; fix the FileCopy size argument; use Q_vsnprintf.
  • common.cpp: guard MSG_ReadBitString and SZ_Print against OOB.
  • cvar.cpp: bound the printable-char copy in Cvar_DirectSet.
  • decals.cpp: reject oversized custom logos.
  • pr_cmds.cpp: guard entnum in PF_SetPhysicsKeyValue.
  • filesystem.cpp / filesystem_internal.cpp: use bounded string copies.
  • sv_remoteaccess.cpp: pass buffer sizes to CUtlBuffer::GetString.
  • mem.cpp: NULL-check the malloc result in Mem_ZeroMalloc.
  • cmd.cpp: bound com_argv access in Cmd_StuffCmds_f.

Filesystem

  • BaseFileSystem.cpp: NULL-check GetWritePath callers, zero-initialize struct _stat, guard StripFilename/FixPath on empty strings, fix FullPathToRelativePath returning false on success.
  • linux_support.cpp: fix scandir namelist handling.

HLTV

  • World.cpp: bound entities and the baseline offset in UncompressEntitiesFromStream (both overloads) — fixes a heap overflow in frameCache_t::entities and a negative-index baseline read.
  • BSPModel.cpp: validate lumps/indices, cap numleafs, fix the PVS buffer off-by-one.
  • DemoPlayer.cpp: NUL-terminate the StringCmd buffer; validate demo sample sizes.
  • NetChannel.cpp: validate the bzip2 size and return value.
  • BitBuffer.cpp / Delta.cpp: bound ReadBitString and DT_STRING.
  • DemoFile.cpp: validate the demo packet length.
  • Proxy.cpp: enlarge the connectionless buffer and initialize outputbuf.

Common

  • ObjectDictionary.cpp: fix OOB in FindClosestAsIndex/RemoveIndexRange/RemoveKey and use memmove.
  • commandline.cpp: enable the bounds checks in LoadParametersFromFile.
  • netapi.cpp / parsemsg.cpp: bounded copies and a READ_FLOAT bounds check.

Harden the engine, filesystem and HLTV against malformed network
packets, BSP/WAD/MDL model files and demo files.

Engine:
- model.cpp: validate every BSP lump offset/size against the file size
  and add planenum/texinfo/children/marksurface/visofs bounds checks in
  Mod_LoadFaces/Nodes/Leafs
- l_studio.cpp: validate .mdl header (length/numtextures/texture
  indices) and per-texture sizes against the actual file size
- wad.cpp: validate WAD header and lump table against the file size
- delta.cpp: bound DT_STRING writes to the destination structure
- hashpak.cpp: validate nFileLength against MAX_FILE_SIZE; fix MD5
  computed over the wrong file handle
- host_cmd.cpp: validate save-game header fields and lightstyle indices;
  fix FileCopy size argument; use Q_vsnprintf
- common.cpp: guard MSG_ReadBitString and SZ_Print against OOB
- cvar.cpp: bound printable-char copy in Cvar_DirectSet
- decals.cpp: reject oversized custom logos
- pr_cmds.cpp: guard entnum in PF_SetPhysicsKeyValue
- filesystem.cpp/filesystem_internal.cpp: use bounded string copies
- sv_remoteaccess.cpp: pass buffer sizes to CUtlBuffer::GetString
- mem.cpp: NULL-check malloc result in Mem_ZeroMalloc
- cmd.cpp: bound com_argv access in Cmd_StuffCmds_f

Filesystem:
- BaseFileSystem.cpp: NULL-check GetWritePath callers, init struct _stat,
  guard StripFilename/FixPath on empty strings, fix FullPathToRelativePath
- linux_support.cpp: fix scandir namelist handling

HLTV:
- World.cpp: bound entities and baseline offset in
  UncompressEntitiesFromStream (both overloads)
- BSPModel.cpp: validate lumps/indices, cap numleafs, fix PVS buffer
  off-by-one
- DemoPlayer.cpp: NUL-terminate StringCmd buffer; validate demo sample
  sizes
- NetChannel.cpp: validate bzip2 size and return value
- BitBuffer.cpp/Delta.cpp: bound ReadBitString and DT_STRING
- DemoFile.cpp: validate demo packet length
- Proxy.cpp: enlarge connectionless buffer and init outputbuf

Common:
- ObjectDictionary.cpp: fix FindClosestAsIndex/RemoveIndexRange/RemoveKey
  OOB and memmove
- commandline.cpp: enable bounds checks in LoadParametersFromFile
- netapi.cpp/parsemsg.cpp: bounded copies and READ_FLOAT bounds check

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant