File tree 1 file changed +10
-2
lines changed
1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -379,8 +379,16 @@ int php_driver_parse_ip_address(char *in, CassInet *inet) {
379
379
int src_pos = compress_pos + move_len - i - 1 ;
380
380
int dst_pos = CASS_INET_V6_LENGTH - i - 1 ;
381
381
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
+ }
384
392
}
385
393
}
386
394
You can’t perform that action at this time.
0 commit comments