Skip to content

Commit

Permalink
Merge pull request #105 from ciaran-moore/v1.3.x
Browse files Browse the repository at this point in the history
Add bounds checking to prevent overflow warnings during build.
  • Loading branch information
CodeLieutenant authored Sep 18, 2024
2 parents 3724bdd + 8212ddd commit a861c1b
Showing 1 changed file with 10 additions and 2 deletions.
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

0 comments on commit a861c1b

Please sign in to comment.