pganalyze / pg_query.rs

Rust library to parse, deparse and normalize SQL queries using the PostgreSQL query parser
MIT License
126 stars 12 forks source link

Fix undefined behavior in `CStr` creation #23

Closed msepga closed 1 year ago

msepga commented 1 year ago

We previously called from_bytes_with_nul_unchecked on a buffer that was generated by prost, and not null-terminated. This is undefined behavior; however it coincidentally continued to work as we didn't do anything with this CStr except get a pointer to the first byte.

Because we didn't do much with this CStr, we can completely remove the undefined behavior and fix the problem by just retrieving a pointer to the buffer start directly.

This was originally caught by running tests through AddressSanitizer.