Skip to content
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

Add bounds checking to prevent overflow warnings during build. #105

Merged
merged 1 commit into from
Sep 18, 2024
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
12 changes: 10 additions & 2 deletions util/src/inet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,16 @@ int php_driver_parse_ip_address(char *in, CassInet *inet) {
int src_pos = compress_pos + move_len - i - 1;
int dst_pos = CASS_INET_V6_LENGTH - i - 1;

address[dst_pos] = address[src_pos];
address[src_pos] = 0;
// Bounds check for src_pos and dst_pos to prevent string overflow
if (src_pos >= 0 && src_pos < CASS_INET_V6_LENGTH && dst_pos >= 0 && dst_pos < CASS_INET_V6_LENGTH) {
address[dst_pos] = address[src_pos];
address[src_pos] = 0;
} else {
// Throw exception if out of bounds
zend_throw_exception_ex(php_driver_invalid_argument_exception_ce, 0,
"Index out of bounds: src_pos = %d, dst_pos = %d, array size = %d",
src_pos, dst_pos, CASS_INET_V6_LENGTH);
}
}
}

Expand Down
Loading