Skip to content

fix: replace sprintf with snprintf to prevent buffer overflows in q3map2#256

Closed
tombudd wants to merge 1 commit intogoogle-deepmind:masterfrom
tombudd:una/fix-sprintf-buffer-overflows
Closed

fix: replace sprintf with snprintf to prevent buffer overflows in q3map2#256
tombudd wants to merge 1 commit intogoogle-deepmind:masterfrom
tombudd:una/fix-sprintf-buffer-overflows

Conversation

@tombudd
Copy link
Copy Markdown

@tombudd tombudd commented Mar 23, 2026

Summary

Convert 11 bare sprintf() calls to snprintf() with sizeof(dest) across the q3map2 map compilation toolchain to prevent buffer overflow vulnerabilities. Found by UNA (autonomous security auditor, designed and built by Tom Buddtom@tombudd.com).

The Problem

The q3map2 toolchain uses sprintf() extensively to format strings into fixed-size buffers. Several of these accept user-controlled input (command-line file paths via ExpandArg(argv[])) that can exceed the destination buffer size, causing stack-based buffer overflows.

Files Changed

File Fixes Key Risk
bsp.c 5 calls User-supplied source paths into 1024-byte out, path, shader buffers
path_init.c 2 calls Home/base/game path concatenation into MAX_OS_PATH (4096) buffers
vis.c 2 calls Expanded argv arguments into global source and portalfile buffers
convert_ase.c 1 call Formatted material names into fixed buffer
bspfile_abstract.c 1 call Temp filenames with timestamps into fixed buffer

Total: 5 files, +11 / -11 lines (mechanical 1:1 replacements)

Why snprintf

Every replacement is sprintf(buf, fmt, ...) → snprintf(buf, sizeof(buf), fmt, ...). This:

  • Prevents writes past the end of the destination buffer
  • Returns the number of characters that would have been written, enabling truncation detection if needed
  • Is a drop-in replacement with identical behavior when the buffer is large enough
  • Introduces zero new dependencies or behavioral changes on success paths

About This Review

This security audit was performed by UNA (Unified Nexus Agent), an autonomous AI security auditor — a Governed Digital Organism (GDO) designed and built by Tom Budd (tom@tombudd.com | tombudd.com).

Convert 11 bare sprintf() calls to snprintf() with sizeof(dest) across
the q3map2 map compilation toolchain:

- bsp.c: 5 calls writing to fixed 1024-byte buffers (out, path, shader)
  using user-supplied source paths from command-line arguments
- path_init.c: 2 calls concatenating home/base/game paths into
  MAX_OS_PATH (4096) buffers — long paths could overflow
- vis.c: 2 calls writing expanded argv arguments into global source
  and portalfile buffers
- convert_ase.c: 1 call writing formatted material names
- bspfile_abstract.c: 1 call writing temp filenames with timestamps

All replacements are mechanical sprintf → snprintf with sizeof(dest),
preserving exact formatting and behavior on success paths.

Reviewed-by: UNA-GDO sovereign-v2.0 (Autonomous Security Auditor)
Built-by: Tom Budd <tom@tombudd.com> — tombudd.com
@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 23, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@tkoeppe
Copy link
Copy Markdown
Collaborator

tkoeppe commented Mar 23, 2026

These are bugs in the upstream ioq3 code, right? We should fix them there, and then pull in an update of the base here.

@tombudd tombudd closed this by deleting the head repository Mar 24, 2026
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.

2 participants