Skip to content

CDRIVER-5641: Build fix for _FORTIFY_SOURCE #1899

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

Merged
1 commit merged into from
Mar 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/libbson/tests/test-bson-vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -1379,14 +1379,24 @@ test_bson_vector_example_packed_bit_view (void)
} else \
((void) 0)

#if defined(__USE_FORTIFY_LEVEL) && __USE_FORTIFY_LEVEL > 0
// Prevent memcpy size overflows even in dead code
#define MAX_TESTABLE_COPY_COUNT (SIZE_MAX / 2u / sizeof (float))
#else
// Allow dead code to contain an oversized or overflowing memcpy
#define MAX_TESTABLE_COPY_COUNT SIZE_MAX
#endif

#define TEST_BSON_VECTOR_EDGE_CASES_RW_COMMON(_view, _alloc_size, _v, _v_size, _read, _write) \
if (true) { \
TEST_BSON_VECTOR_RW (false, (_view), (_v), (_alloc_size) + 1u, 0, (_read), (_write)); \
TEST_BSON_VECTOR_RW (true, (_view), (_v), (_v_size), (_alloc_size) - (_v_size), (_read), (_write)); \
TEST_BSON_VECTOR_RW (false, (_view), (_v), (_v_size), (_alloc_size) - (_v_size) + 1u, (_read), (_write)); \
TEST_BSON_VECTOR_RW (false, (_view), (_v), (_v_size) + 1u, (_alloc_size) - (_v_size), (_read), (_write)); \
TEST_BSON_VECTOR_RW (false, (_view), (_v), SIZE_MAX, (_alloc_size) - (_v_size), (_read), (_write)); \
TEST_BSON_VECTOR_RW (false, (_view), (_v), SIZE_MAX, (_alloc_size) - (_v_size) + 1u, (_read), (_write)); \
TEST_BSON_VECTOR_RW ( \
false, (_view), (_v), MAX_TESTABLE_COPY_COUNT, (_alloc_size) - (_v_size), (_read), (_write)); \
TEST_BSON_VECTOR_RW ( \
false, (_view), (_v), MAX_TESTABLE_COPY_COUNT, (_alloc_size) - (_v_size) + 1u, (_read), (_write)); \
TEST_BSON_VECTOR_RW (true, (_view), (_v), (_v_size), 0, (_read), (_write)); \
} else \
((void) 0)
Expand Down