Skip to content

ioconf: Explicitly terminate dfmt after truncation - #467

Merged
sysstat merged 1 commit into
sysstat:masterfrom
natoscott:fix/ioconf-dfmt-truncation
Nov 22, 2026
Merged

sysstat merged 1 commit into
sysstat:masterfrom
natoscott:fix/ioconf-dfmt-truncation

Conversation

@natoscott

@natoscott natoscott commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

GCC reports a -Wstringop-truncation warning in ioc_init():

ioconf.c:321:25: warning: 'strncpy' output may be truncated copying 13 bytes from a string of length 14 [-Wstringop-truncation]

The devfmt field may contain up to 15 characters. After stripping the
leading %, dfmt + 1 can hold 14 characters, but only 13 can be copied
to blkp->dfmt to leave room for the "%s" appended by the fallthrough.

The truncation is intentional and was safe because blkp is zeroed
earlier, but the NUL termination relied implicitly on that memset().
Terminate the destination explicitly instead. No functional change.

GCC reports:

  ioconf.c:321:25: warning: 'strncpy' output may be truncated copying 13 bytes from a string of length 14 [-Wstringop-truncation]

The devfmt field may contain up to 15 characters. In the '%' case the
leading '%' is stripped, so dfmt + 1 can hold 14 characters, but only 13
can be copied to blkp->dfmt to leave room for the "%s" appended by the
fallthrough. The truncation is intentional, and the buffer was zeroed
earlier in the function, so it was safe. Explicitly terminate the result
instead of relying on that earlier memset(), and use the parser-friendly
"fall through" comment to avoid -Wimplicit-fallthrough.

No functional change.
@sysstat
sysstat merged commit 35572ad into sysstat:master Nov 22, 2026
3 of 7 checks passed
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