Commit 470eea7
committed
fix(rest): fix getNetworkDiagnosticTask off-by-one crash
DiagnosticTypes::kKeyMap has 27 entries (ids 0-9, 14-17, 19-21,
23-31, 34), but DiagnosticTypes::kMaxTotalCount was set to 26.
This caused an assertion failure and crashed the otbr-agent
root daemon whenever a REST call requested all 27 valid types.
In NDEBUG builds, this led to a 1-byte out-of-bounds write.
This commit addresses the issue by:
1. Increasing kMaxTotalCount to 27.
2. Implementing compile-time static_assert checks using recursive
constexpr helper functions to dynamically validate kMaxTotalCount,
kMaxQueryCount, and kMaxResettableCount against the key map table,
preventing future off-by-one regressions.
3. Validating request types array size in NetworkDiagnostic::Validate
to ensure the unique type count does not exceed kMaxTotalCount.1 parent 07ec9a0 commit 470eea7
2 files changed
Lines changed: 43 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
209 | | - | |
210 | 209 | | |
211 | | - | |
212 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
213 | 218 | | |
214 | 219 | | |
215 | 220 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
48 | 75 | | |
49 | 76 | | |
50 | 77 | | |
| |||
109 | 136 | | |
110 | 137 | | |
111 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
112 | 146 | | |
113 | 147 | | |
114 | 148 | | |
| |||
0 commit comments