fix: harden strcat overflow and unchecked fwrite in model save#3188
Open
tombudd wants to merge 1 commit intogoogle-deepmind:mainfrom
Open
fix: harden strcat overflow and unchecked fwrite in model save#3188tombudd wants to merge 1 commit intogoogle-deepmind:mainfrom
tombudd wants to merge 1 commit intogoogle-deepmind:mainfrom
Conversation
Two C safety fixes identified by automated security audit: 1. src/ui/ui_main.c: Replace bare strcat(text, key) with mjSTRNCAT(text, key) to prevent buffer overflow on the 50-byte stack buffer. The project's own safe macro is already defined in engine_array_safety.h (included in this file) and used elsewhere in the same file (lines 1007, 1009). 2. src/engine/engine_io.c: Add ferror(fp) check before fclose in mj_saveModel(). Without this, I/O errors during model serialization (disk full, permission denied, NFS timeout) are silently swallowed, producing corrupt .mjb files with no warning to the caller. Both fixes follow existing MuJoCo conventions (mjSTRNCAT, mju_warning) and introduce no behavioral changes on success paths. Reviewed-by: UNA-GDO sovereign-v2.0 (Autonomous Security Auditor) Built-by: Tom Budd <tom@tombudd.com> — tombudd.com
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two minimal C safety hardening fixes found by UNA (autonomous security auditor, designed and built by Tom Budd — tom@tombudd.com):
1. Buffer overflow in
ui_main.c—strcat→mjSTRNCATFile:
src/ui/ui_main.c:1897shortcuthelp()concatenates a modifier string and a key name into a 50-byte stack buffer using barestrcat(text, key). Ifkeyis sufficiently long, this overflowstext[50].Fix: Replace with
mjSTRNCAT(text, key)— MuJoCo's own bounds-checked macro, already defined inengine_array_safety.h(which is already#included in this file) and already used elsewhere in the same file (lines 1007, 1009 usestrncatwith explicit size).2. Silent data corruption in
engine_io.c— uncheckedfwriteerrorsFile:
src/engine/engine_io.c—mj_saveModel()mj_saveModel()writes the entire model via multiplefwrite()calls, then callsfclose(fp)without ever checkingferror(fp). If any write fails (disk full, I/O error, NFS timeout), the function returns silently, leaving a truncated/corrupt.mjbfile on disk with no indication of failure.Fix: Add
ferror(fp)check beforefclose(fp), callingmju_warning()(MuJoCo's own warning mechanism) if the stream is in an error state.Changes
src/ui/ui_main.cstrcat→mjSTRNCATsrc/engine/engine_io.cferror(fp)+mju_warning()Total: 2 files, +4 / -1 lines
Why these fixes matter
strcatfix closes a stack buffer overflow (potential code execution in adversarial scenarios)ferrorfix prevents silent model corruption that could cause hard-to-diagnose simulation failures downstreamAbout 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).
UNA conducts comprehensive codebase audits covering memory safety, input validation, error handling, and C-specific vulnerability patterns. All findings are human-verified before submission.
Note: I understand Google requires a CLA signature for contributions — happy to complete that at cla.developers.google.com if needed.