Commit 48303c5
Fix integer overflow in TLVReader::GetString bounds check (project-chip#71934)
* Fix integer overflow in TLVReader::GetString bounds check
The bounds check `(mElemLenOrVal + 1) > bufSize` can wrap to 0 when
mElemLenOrVal is large (e.g., UINT32_MAX on 32-bit targets), bypassing
the buffer size validation and causing an out-of-bounds write of the
null terminator.
Replace with `mElemLenOrVal >= bufSize` which is overflow-safe and
semantically equivalent. Also pass the actual element length to GetBytes
instead of bufSize-1.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Add larger-buffer test case for GetString per review feedback
Verifies that GetString with a buffer larger than the string content
succeeds correctly, confirming that GetBytes is called with the actual
element length rather than bufSize-1.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Retrigger CI (REPL timeout)
* Retrigger CI (nRF/REPL flake)
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Andrei Litvin <andy314@gmail.com>1 parent 20fcb76 commit 48303c5
2 files changed
Lines changed: 65 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
441 | 441 | | |
442 | 442 | | |
443 | 443 | | |
444 | | - | |
| 444 | + | |
445 | 445 | | |
446 | 446 | | |
447 | 447 | | |
448 | 448 | | |
449 | | - | |
| 449 | + | |
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4946 | 4946 | | |
4947 | 4947 | | |
4948 | 4948 | | |
| 4949 | + | |
| 4950 | + | |
| 4951 | + | |
| 4952 | + | |
| 4953 | + | |
| 4954 | + | |
| 4955 | + | |
| 4956 | + | |
| 4957 | + | |
| 4958 | + | |
| 4959 | + | |
| 4960 | + | |
| 4961 | + | |
| 4962 | + | |
| 4963 | + | |
| 4964 | + | |
| 4965 | + | |
| 4966 | + | |
| 4967 | + | |
| 4968 | + | |
| 4969 | + | |
| 4970 | + | |
| 4971 | + | |
| 4972 | + | |
| 4973 | + | |
| 4974 | + | |
| 4975 | + | |
| 4976 | + | |
| 4977 | + | |
| 4978 | + | |
| 4979 | + | |
| 4980 | + | |
| 4981 | + | |
| 4982 | + | |
| 4983 | + | |
| 4984 | + | |
| 4985 | + | |
| 4986 | + | |
| 4987 | + | |
| 4988 | + | |
| 4989 | + | |
| 4990 | + | |
| 4991 | + | |
| 4992 | + | |
| 4993 | + | |
| 4994 | + | |
| 4995 | + | |
| 4996 | + | |
| 4997 | + | |
| 4998 | + | |
| 4999 | + | |
| 5000 | + | |
| 5001 | + | |
| 5002 | + | |
| 5003 | + | |
| 5004 | + | |
| 5005 | + | |
| 5006 | + | |
| 5007 | + | |
| 5008 | + | |
| 5009 | + | |
| 5010 | + | |
| 5011 | + | |
0 commit comments