awslabs/aws-c-common

Undefined Behaviour in aws_byte_buf_init_cache_and_update_cursors?

gitusel opened this issue · 1 comments

I was testing byte_buf and in particular the test "test_byte_buf_init_cache_and_update_cursors". For the tests "store empty string cursor" and "zeroed out cursor", the call to the aws_byte_buf_append_and_update function does not check if to->buffer is null. In these 2 tests, to->len and from_and_update->len are also equal to zero making the line

from_and_update->ptr = to->buffer + (to->len - from_and_update->len);

a UB in C (null pointer arithmetic is UB for any offset including 0) but may not be in C++ (only non-zero offset).

Thanks for reporting this. It has been fixed in #999