-
Notifications
You must be signed in to change notification settings - Fork 35
Fix integer overflow-prone offset+len bounds checks in NVM read handlers #319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -562,6 +562,29 @@ static int _testOutOfBoundsNvmReads(whClientContext* client, | |
| wh_Client_NvmReadResponse(client, &server_rc, &len, buffer)); | ||
| WH_TEST_ASSERT_RETURN(server_rc == WH_ERROR_BADARGS); | ||
|
|
||
| /* Test with large offset (UINT16_MAX), should fail since offset >= | ||
| * meta.len. Regression test for integer overflow safety in the | ||
| * offset+len check */ | ||
| off = UINT16_MAX; | ||
| len = 1; | ||
| WH_TEST_RETURN_ON_FAIL(wh_Client_NvmReadRequest(client, id, off, len)); | ||
| WH_TEST_RETURN_ON_FAIL(wh_Server_HandleRequestMessage(server)); | ||
| WH_TEST_RETURN_ON_FAIL( | ||
| wh_Client_NvmReadResponse(client, &server_rc, &len, buffer)); | ||
| WH_TEST_ASSERT_RETURN(server_rc == WH_ERROR_BADARGS); | ||
|
|
||
| /* Test clamping with offset at midpoint and len exceeding remaining object | ||
| * size. Verifies the overflow-safe comparison (len > meta.len - offset) | ||
| * correctly clamps when offset + len would exceed meta.len */ | ||
|
Comment on lines
+577
to
+578
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This new test doesn't actually test your fix FYI but there isn't a good way to test it. The first test is caught by the pre-existing offset >= meta.len guard before reaching the changed line. This one exercises the clamping logic but with values too small to trigger any overflow |
||
| off = meta.len / 2; | ||
| len = meta.len; | ||
| WH_TEST_RETURN_ON_FAIL(wh_Client_NvmReadRequest(client, id, off, len)); | ||
| WH_TEST_RETURN_ON_FAIL(wh_Server_HandleRequestMessage(server)); | ||
| WH_TEST_RETURN_ON_FAIL( | ||
| wh_Client_NvmReadResponse(client, &server_rc, &len, buffer)); | ||
| WH_TEST_ASSERT_RETURN(server_rc == WH_ERROR_OK); | ||
| WH_TEST_ASSERT_RETURN(len == meta.len - meta.len / 2); | ||
|
|
||
| return WH_ERROR_OK; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.