Repository navigation
refactor(security): harden legacy C string functions and buffer bounds - #52
Merged
Merged
Conversation
Audit and refactor unsafe string and buffer handling in core application code: - Replace unbounded `sprintf` and `vsprintf` with `snprintf` and `vsnprintf` - Replace `strcpy` with `strncpy` or safe `memcpy` with explicit bounds - In `RvApplication`: use `QString::asprintf` for about dialog, use `std::string` and `unsigned char` casts for URL decoding and hex encoding - In `StringType::String::set` and `setn`: replace unconstrained `strcpy` with bounded `memcpy` - In `PanavisionLUT.cpp`: remove fixed 64-byte stack buffer and parse integers directly from string offset - In `MovieFFMpeg`: widen `charRotation` buffer and use `snprintf` - In command-line entry points: avoid modifying `argv` via in-place `strcpy` - In GTO and Mu parsers/lexers: guard error and warning format strings with bounds checking Refs: #51 Signed-off-by: Michael Oliver <mcoliver@gmail.com>
4 tasks
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.
Description
Audit and refactor unsafe legacy C string functions (
sprintf,vsprintf,strcpy) and buffer boundaries across first-party core code in OpenUTV.Summary of Hardening:
Unbounded Formatted Printing (
sprintf/vsprintf):src/lib/andsrc/bin/tosnprintf/vsnprintfwith explicit buffer bounds:src/lib/image/MovieFFMpeg/MovieFFMpeg.cpp: rotation string formatting and audio metadata attributes.src/lib/image/IOdpx/IOdpx.cpp: timecode calculation and header descriptor attributes.src/lib/image/IOpng/IOpng.cpp,IOjpeg/IOjpeg.cpp,IOtiff/IOtiff.cpp,IOz/IOz.cpp,IOmray/IOmray.cpp,TwkImg/TwkImgSgiIff.cpp.src/lib/app/RvApp/RvSession.cpp,RvGraph.cpp,src/lib/ip/IPCore/IPGraph.cpp,Session.cpp,SourceGroupIPNode.cpp: unique node naming logic (eliminated thread-unsafe static buffers and unconstrainedsprintf).src/lib/base/TwkUtil/Notifier.cpp: object address formatting.src/lib/files/Gto/Parser.y,Writer.cpp: reader/writer formatted error/warning reporting withvsnprintfand missingva_endcleanup.src/lib/mu/Mu/&MuLang/: compiler & assembler error reporting (NodeAssembler.cpp,Grammar.y), parameter naming (FunctionSpecializer.cpp,TupleType.cpp,PartialApplicator.cpp,FixedArrayType.cpp,DynamicArrayType.cpp,MuLangContext.cpp), and primitive string serialization (StringType.cpp).Unchecked String Copying (
strcpy):PanavisionLUT.cpp: Removed stack buffer andstrcpyentirely when parsing entries header.RvApplication.cpp:char[]buffer andstrcpyin baked URL decoding with safestd::stringaccumulation.unsigned char(preventing negative-char expansion buffer overflow) and usingsnprintf.vector<char>withQString::asprintffor the About dialog.StringType.cpp: ReplacedstrcpywithmemcpyinStringType::String::setandsetnbounded by size (preventing out-of-bounds reads and overflows on non-null-terminated buffers).MovieSideCar/Common.cpp: Replacedstrcpywithstrncpybounded byMessage::SizeInBytes().TwkImgCineonIff.cpp: Replacedstrcpywithstrncpybounded by header field sizes.main.cppacross CLI executables (rv,utv,rvpkg,rvio): Replaced in-placestrcpy(argv[i], "-help")with direct pointer reassignment.Lexer.l&Grammar.y: Bounded operator token copying into_op[4]withstrncpy.Closes #51