Fix missing NUL termination after strncpy()#5042
Open
peripherium wants to merge 1 commit intoMidnightCommander:masterfrom
Open
Fix missing NUL termination after strncpy()#5042peripherium wants to merge 1 commit intoMidnightCommander:masterfrom
peripherium wants to merge 1 commit intoMidnightCommander:masterfrom
Conversation
8480e3e to
b0d6c82
Compare
mc-worker
approved these changes
Mar 6, 2026
Contributor
|
Fixes 260126a. |
Contributor
|
/rebase |
Signed-off-by: Manuel Einfalt <einfalt1@proton.me>
b0d6c82 to
5f0017d
Compare
Member
|
I wish we had a test for this function, especially when a bug is getting fixed. @peripherium, would you be up for the task? I have added a test under similar circumstances; you can check this as an example: 7488fc5 . |
Contributor
|
I build mc from last commit 9f0be66 and now can't open any tgz archive (after open one). Always get an error: |
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.

strncpy() was called with text->len, which does not include the terminating NUL byte. As a result, when a shorter filename was copied after a longer one, the global buffer retained trailing characters from the previous value, producing an invalid path.
The fix copies text->len + 1 bytes to include the guaranteed NUL terminator provided by GString.