Skip to content

Replace strncpy() with strscpy helpers - #94

Merged
jserv merged 1 commit into
sysprog21:masterfrom
EricKim27:master
Aug 6, 2026
Merged

Replace strncpy() with strscpy helpers#94
jserv merged 1 commit into
sysprog21:masterfrom
EricKim27:master

Conversation

@EricKim27

@EricKim27 EricKim27 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

It has been discouraged in linux kernel to use strncpy() as it had been a persistent source of
bugs due to its ambiguous intent and counter-intuitive semantics.
And because of that, it was removed from linux kernel 7.2.

Replace strncpy() with strscpy() which provides more safer string copying semantics
and guarantees null termination when destination buffer is non-empty.

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=079a028d6327e68cfa5d38b36123637b321c19a7


Summary by cubic

Replace strncpy() with strscpy() and strscpy_pad() in inode.c and super.c for safer string copying with guaranteed null-termination and proper padding. This prevents silent truncation and keeps the filesystem compatible with kernels that removed strncpy().

  • Bug Fixes
    • Use strscpy_pad() for directory filenames and rename paths to fill fixed-size fields.
    • Use strscpy() for symlink i_data and when writing inode i_data to disk.

Written for commit 24a219e. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed against the latest diff

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread inode.c Outdated
It has been discouraged in linux kernel to use
strncpy() as it had been a persistent source of
bugs due to its ambiguous intent and counter-intuitive
semantics. And because of that, it was removed from
linux kernel 7.2.

Replace strncpy() with strscpy() for null termination and
strscpy_pad() for null terminations with padding which provides
more safer string copying semantics and guarantees null termination
when destination buffer is non-empty.
@EricKim27 EricKim27 changed the title Replace strncpy() with strscpy() Replace strncpy() with strscpy helpers Aug 6, 2026
@jserv
jserv merged commit 09a88f0 into sysprog21:master Aug 6, 2026
4 checks passed
@jserv

jserv commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Thank @EricKim27 for contributing!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants