Skip to content

Fix missing NUL termination after strncpy()#5042

Open
peripherium wants to merge 1 commit intoMidnightCommander:masterfrom
peripherium:fix/add-null-termination
Open

Fix missing NUL termination after strncpy()#5042
peripherium wants to merge 1 commit intoMidnightCommander:masterfrom
peripherium:fix/add-null-termination

Conversation

@peripherium
Copy link

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.

@github-actions github-actions bot added needs triage Needs triage by maintainers prio: medium Has the potential to affect progress labels Mar 4, 2026
@github-actions github-actions bot added this to the Future Releases milestone Mar 4, 2026
@peripherium peripherium force-pushed the fix/add-null-termination branch from 8480e3e to b0d6c82 Compare March 4, 2026 15:42
@mc-worker mc-worker added area: core Issues not related to a specific subsystem and removed needs triage Needs triage by maintainers labels Mar 6, 2026
@mc-worker mc-worker requested review from aborodin and mc-worker and removed request for aborodin March 6, 2026 16:47
@mc-worker
Copy link
Contributor

Fixes 260126a.

@mc-worker
Copy link
Contributor

/rebase

@mc-worker mc-worker modified the milestones: Future Releases, 4.9.0 Mar 6, 2026
Signed-off-by: Manuel Einfalt <einfalt1@proton.me>
@mc-butler mc-butler force-pushed the fix/add-null-termination branch from b0d6c82 to 5f0017d Compare March 6, 2026 16:50
@zyv
Copy link
Member

zyv commented Mar 6, 2026

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 .

@KuzinAndrey
Copy link
Contributor

I build mc from last commit 9f0be66 and now can't open any tgz archive (after open one). Always get an error:
1
But this fix is help to return to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Issues not related to a specific subsystem prio: medium Has the potential to affect progress

Development

Successfully merging this pull request may close these issues.

4 participants