Skip to content

Fix the warnings gcc reports on 7.1 headers (maybe-uninitialized 74, format-truncation 5, frame-larger-than 1 -> 0) - #41

Open
iav wants to merge 7 commits into
jethome-iot:tune_for_jethubfrom
iav:fix/warnings-7.1
Open

Fix the warnings gcc reports on 7.1 headers (maybe-uninitialized 74, format-truncation 5, frame-larger-than 1 -> 0)#41
iav wants to merge 7 commits into
jethome-iot:tune_for_jethubfrom
iav:fix/warnings-7.1

Conversation

@iav

@iav iav commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Building the driver against 7.1 headers (arm64, Armbian meson64 config,
gcc 13) reports 80 warnings that 6.x kernels do not show:

  • proc write handlers (rtw_debug.c, rtw_proc.c): zero-initialise the
    scratch buffers (110) and reject count >= sizeof(tmp) instead of >
    (141) - a write of exactly sizeof bytes left the string unterminated.
    proc_set_pathb_phase copied with no upper bound at all into a 255-byte
    stack buffer; it now checks like the others.
  • mp ioctl: input[] = {0} (25). The length is already bounded by
    rtw_do_mp_iwdata_len_chk(); this only lets gcc prove the buffer defined.
  • rtw_add_bcn_ie: ielen = 0 (only read when p != NULL; gcc cannot connect
    the two).
  • rtw_rf.c: fmt[16] -> [32] with sizeof; SDIO xmit thread_name 20 -> 32
    ("RTWHALXT-" + IFNAMSIZ).
  • rtw_cfg80211_indicate_connect: cfg80211_roam_info (>1 KB) on the heap
    for the cfg80211_roamed() call.

Result: -Wmaybe-uninitialized 74 -> 0, -Wformat-truncation 5 -> 0,
-Wframe-larger-than 1 -> 0, no errors, .ko links. -Wunused-function stays
at 0 on 7.1 with #30/#32.

iav added 7 commits August 16, 2026 15:07
On 7.1 headers copy_from_user() is checked through check_object_size()
and gcc reports every uninitialised local target as
-Wmaybe-uninitialized. Zero-initialising the buffers proves them
defined and also guarantees the parsed string is terminated when the
copy fills the buffer short of its end.
The write handlers copy count bytes into a fixed buffer and parse it as
a string; a write of exactly sizeof(tmp) bytes filled the buffer with no
terminator. Reject count >= sizeof(tmp) so the last byte stays zero.
The handler copied count bytes into a 255-byte stack buffer with no
upper bound; every other write handler rejects oversized input first.
Add the same check.
Every handler already bounds wrqu->length with rtw_do_mp_iwdata_len_chk()
before the copy, so this only lets gcc prove the buffer defined for the
subsequent parsing (-Wmaybe-uninitialized through check_object_size on
7.1 headers).
ielen is only assigned when the loop finds the element; the check after
the loop tests p != NULL first, so the read is guarded in practice, but
gcc cannot connect the two (-Wmaybe-uninitialized). Start from 0.
rtw_rf.c builds a printf format with %zu into a 16-byte buffer, which
gcc cannot prove fits; size it to 32 and pass sizeof. The SDIO xmit
thread name is "RTWHALXT-" plus the interface name (up to IFNAMSIZ), so
20 bytes may truncate; use 32.
struct cfg80211_roam_info is over a kilobyte on recent kernels and
pushes the frame past the 1024-byte limit (-Wframe-larger-than). Allocate
it for the duration of the cfg80211_roamed() call; if the allocation
fails the roam is logged and not reported. The connect-result path is
unaffected.
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.

1 participant