fix(lib,scheduler): zarray_get rejects negative indexes; info resource bounds by capacity (bug-1824)
zarray_get_ex() checked only idx >= caps, so a negative index read array->data[idx] out of bounds -- reachable through a resource whose registration failed and kept idx == -1 (xcelimit.c add_vres()). It now returns NULL for idx < 0. repl_info_resource_one() bounded a shared resource's slot by sharedInst.count / sharedInUse.count, the number of populated slots, not the capacity: a populated slot above that count showed as value=(none). It now relies on zarray_get()'s own bounds check. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
fd61721bab
commit
16b7aa4b60
4 changed files with 90 additions and 11 deletions
|
|
@ -210,6 +210,25 @@ static void test_zarray_fini_resets_bounds_for_reuse()
|
|||
zarray_fini(&array);
|
||||
}
|
||||
|
||||
|
||||
/* bug-1824: zarray_get_ex() only checked idx >= caps, so a negative index
|
||||
* read array->data[idx] out of bounds. A resource whose registration fails
|
||||
* keeps idx == -1 (xcelimit.c add_vres()), so a caller can pass one. */
|
||||
static void test_zarray_get_negative_index_returns_null(void)
|
||||
{
|
||||
zarray_t z;
|
||||
int v = 7;
|
||||
|
||||
zarray_init(&z, 4, NULL);
|
||||
TEST_ASSERT_TRUE(zarray_put(&z, 0, &v) >= 0);
|
||||
|
||||
TEST_ASSERT_NULL(zarray_get(&z, -1));
|
||||
TEST_ASSERT_NULL(zarray_get(&z, -1000));
|
||||
TEST_ASSERT_EQUAL_PTR(&v, zarray_get(&z, 0));
|
||||
|
||||
zarray_fini(&z);
|
||||
}
|
||||
|
||||
void test_zarray(void)
|
||||
{
|
||||
printf("\n>> zarray test\n\n");
|
||||
|
|
@ -221,4 +240,5 @@ void test_zarray(void)
|
|||
RUN_TEST(test_zarray_put_get_vec);
|
||||
RUN_TEST(test_zarray_iter);
|
||||
RUN_TEST(test_zarray_fini_resets_bounds_for_reuse);
|
||||
RUN_TEST(test_zarray_get_negative_index_returns_null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -350,7 +350,8 @@ int zarray_get_ex(zarray_t* array, int count, int* idxs, void** data)
|
|||
for (i = 0; i < count; i++) {
|
||||
int idx = idxs[i];
|
||||
|
||||
if (idx >= array->caps) {
|
||||
/* bug-1824: a negative idx read array->data[idx] out of bounds */
|
||||
if ((idx < 0) || (idx >= array->caps)) {
|
||||
data[i] = NULL;
|
||||
} else {
|
||||
data[i] = array->data[idx];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue