Fix executable path truncation and copied-file error message - #272
Draft
rootkiller6788 wants to merge 1 commit into
Draft
Fix executable path truncation and copied-file error message#272rootkiller6788 wants to merge 1 commit into
rootkiller6788 wants to merge 1 commit into
Conversation
getLinuxSelfExePath() compared readlink()'s return value against sizeof(buf), which for a char* parameter is the pointer size, not the buffer length. A path exactly 8 characters long was treated as an error, and a truncated path (one that fills the buffer) wrote a terminating null one byte past the end of the buffer. Compare against buflen instead, and treat a full-buffer read as a failure. Also, when the copied output file fails to open, VrsCommand reported the source file's path instead of the destination path that actually failed.
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 small error-handling fixes in the
vrstools, both verified against currentmain(a6a3ad9).1.
os::Utils::getLinuxSelfExePath()— wrong buffer-size comparison, potential out-of-bounds writegetLinuxSelfExePath()comparedreadlink()'s return value againstsizeof(buf). Inside the functionbufis achar*, sosizeof(buf)is the pointer size (8 on 64-bit), not the caller-provided buffer lengthbuflen. On Linux/Android this caused two problems:getCurrentExecutablePath()return an empty string (used for temp-folder naming).readlink()fills the whole buffer (path length >= PATH_MAX, i.e. a truncated path), the returned length equalsbuflen, andbuf[len] = '\0'wrote one byte past the end of the caller'schar exePath[PATH_MAX]stack buffer.The fix compares against
buflenand treats a full-buffer read (truncated path) as a failure, so a terminating null is never written past the buffer.2.
VrsCommand::doCopyMerge()— wrong path in "could not open copied file" errorWhen re-opening the output file after a
copy/mergefailed (outputFile.openFile(targetPath)), the error message printed the source file's path (filteredReader.getPathOrUri()) instead of the destination path that actually failed to open. It now reportstargetPath.Verification
getLinuxSelfExePathboundary behavior (readlink error, exactly-8-char path, full-buffer truncation) checked against the old vs new logic; the change is Linux/Android-only and leaves the Windows/macOS paths untouched.VrsCommand::doCopyMergeerror path: the reported path now matches the file passed tooutputFile.openFile().