Commit a467602
committed
audio: kpb: widen channel loop counter to match micsel_channels
The four kpb_micselect_copy16/32() variants declare the channel loop
counter "ch" as uint16_t while iterating "for (ch = 0; ch < ...
micsel_channels; ch++)", where micsel_channels is uint32_t. The loop
condition promotes ch to a wider type for the comparison, so if
micsel_channels ever exceeds UINT16_MAX the counter wraps at 65536 and
the loop fails to terminate. The same narrow counter would also
truncate channel indexing.
Declare ch as uint32_t so its width matches the bound it is compared
against and the channel count it indexes. KPB_MAX_MICSEL_CHANNELS keeps
the real value small, so this is hardening rather than an observed
runaway, but the type mismatch is removed at the source.
CodeQL flagged the two non-HiFi variants (kpb.c:1112,1143); the two
KPB_HIFI3 variants (kpb.c:1050,1084) carry the identical pattern and
are fixed in the same change for consistency.
Found-by: CodeQL 2.24.2 (codeql/cpp-queries cpp-security-extended),
rule cpp/comparison-with-wider-type. Run with database
build-mode=none over sof/src, 867 files / 98 queries.
AI-triaged: traced ch and micsel_channels declarations across all four
micselect copy functions and confirmed the bound is uint32_t before
widening the counter; extended the fix to the HiFi3 variants the tool
did not reach in this build configuration.
Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>1 parent aca3c55 commit a467602
1 file changed
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1033 | 1033 | | |
1034 | 1034 | | |
1035 | 1035 | | |
1036 | | - | |
| 1036 | + | |
1037 | 1037 | | |
1038 | 1038 | | |
1039 | 1039 | | |
| |||
1066 | 1066 | | |
1067 | 1067 | | |
1068 | 1068 | | |
1069 | | - | |
| 1069 | + | |
1070 | 1070 | | |
1071 | 1071 | | |
1072 | 1072 | | |
| |||
1103 | 1103 | | |
1104 | 1104 | | |
1105 | 1105 | | |
1106 | | - | |
| 1106 | + | |
1107 | 1107 | | |
1108 | 1108 | | |
1109 | 1109 | | |
| |||
1135 | 1135 | | |
1136 | 1136 | | |
1137 | 1137 | | |
1138 | | - | |
| 1138 | + | |
1139 | 1139 | | |
1140 | 1140 | | |
1141 | 1141 | | |
| |||
0 commit comments