Commit cba5ffd
committed
Fix NULL pointer dereference in SCCB accessor functions
get_handle_from_address() returns NULL when the given slave address
isn't registered in devices[] (e.g. after SCCB_Deinit(), or a
concurrent deinit racing an in-flight transaction), logging
"Device with address %02x not found" as a designed graceful-failure
path. All 6 accessor functions (SCCB_Read, SCCB_Write, SCCB_Read16,
SCCB_Write16, SCCB_Read_Addr16_Val16, SCCB_Write_Addr16_Val16)
dereferenced that return value unconditionally, turning the intended
error path into a NULL pointer dereference / crash.
Add a NULL check before each dereference, returning the same failure
value each function already uses for I2C errors (0 for reads, -1 for
writes), consistent with this file's existing error-handling
convention.1 parent 202df95 commit cba5ffd
1 file changed
Lines changed: 36 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
228 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
229 | 234 | | |
230 | 235 | | |
231 | 236 | | |
| |||
267 | 272 | | |
268 | 273 | | |
269 | 274 | | |
270 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
271 | 281 | | |
272 | 282 | | |
273 | 283 | | |
| |||
285 | 295 | | |
286 | 296 | | |
287 | 297 | | |
288 | | - | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
289 | 304 | | |
290 | 305 | | |
291 | 306 | | |
| |||
304 | 319 | | |
305 | 320 | | |
306 | 321 | | |
307 | | - | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
308 | 328 | | |
309 | 329 | | |
310 | 330 | | |
| |||
322 | 342 | | |
323 | 343 | | |
324 | 344 | | |
325 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
326 | 351 | | |
327 | 352 | | |
328 | 353 | | |
| |||
342 | 367 | | |
343 | 368 | | |
344 | 369 | | |
345 | | - | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
346 | 376 | | |
347 | 377 | | |
348 | 378 | | |
| |||
0 commit comments