Skip to content

Commit a861c1b

Browse files
Merge pull request he4rt#105 from ciaran-moore/v1.3.x
Add bounds checking to prevent overflow warnings during build.
2 parents 3724bdd + 8212ddd commit a861c1b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Diff for: util/src/inet.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,16 @@ int php_driver_parse_ip_address(char *in, CassInet *inet) {
379379
int src_pos = compress_pos + move_len - i - 1;
380380
int dst_pos = CASS_INET_V6_LENGTH - i - 1;
381381

382-
address[dst_pos] = address[src_pos];
383-
address[src_pos] = 0;
382+
// Bounds check for src_pos and dst_pos to prevent string overflow
383+
if (src_pos >= 0 && src_pos < CASS_INET_V6_LENGTH && dst_pos >= 0 && dst_pos < CASS_INET_V6_LENGTH) {
384+
address[dst_pos] = address[src_pos];
385+
address[src_pos] = 0;
386+
} else {
387+
// Throw exception if out of bounds
388+
zend_throw_exception_ex(php_driver_invalid_argument_exception_ce, 0,
389+
"Index out of bounds: src_pos = %d, dst_pos = %d, array size = %d",
390+
src_pos, dst_pos, CASS_INET_V6_LENGTH);
391+
}
384392
}
385393
}
386394

0 commit comments

Comments
 (0)