Bug 346228 - Linux/diskstats.c:192: off by one error ?
Summary: Linux/diskstats.c:192: off by one error ?
Status: RESOLVED FIXED
Alias: None
Product: ksysguard
Classification: Unmaintained
Component: ksysguardd (show other bugs)
Version: 5.2.2
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: KSysGuard Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-15 18:10 UTC by dcb314
Modified: 2020-07-01 13:06 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dcb314 2015-04-15 18:10:31 UTC
[../../../ksysguardd/Linux/diskstats.c:192]: (error) Width 20 given in format string (no. 3) is larger than destination buffer 'devname[20]', use %19s to prevent overflowing it.

    switch (sscanf(buf, "%d %d %" TOSTRING(DISKDEVNAMELEN) "s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",


Reproducible: Always
Comment 1 Marco Martin 2015-04-16 08:49:21 UTC
is it a console output or build error?
Comment 2 dcb314 2015-04-16 08:58:27 UTC
Not sure how it matters, but basically a build error.

I ran static analyser cppcheck over the code.
Comment 3 Bug Janitor Service 2020-06-27 20:21:26 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/ksysguard/-/merge_requests/20
Comment 4 groot 2020-06-27 20:22:35 UTC
Confirmed, with a really long disk device name the terminating NUL (written by sscanf) falls outside the buffer. I just filed a MR in invent to fix it.
Comment 5 Arjen Hiemstra 2020-07-01 13:06:34 UTC
Git commit 566d5faba288c9abdbc8436fea43d4c7207ea41e by Arjen Hiemstra, on behalf of Adriaan de Groot.
Committed on 01/07/2020 at 13:06.
Pushed by ahiemstra into branch 'master'.

Fix buffer-overflow

The buffer for a sscanf() %s argument with a length needs to be
1 longer than the length, for the terminating NUL.

M  +6    -2    ksysguardd/Linux/diskstats.c

https://invent.kde.org/plasma/ksysguard/commit/566d5faba288c9abdbc8436fea43d4c7207ea41e