statsd-filter-proxy-rs icon indicating copy to clipboard operation
statsd-filter-proxy-rs copied to clipboard

Calling safe function can lead to undefined behaviour

Open gpluscb opened this issue 4 years ago • 0 comments

https://github.com/askldjd/statsd-filter-proxy-rs/blob/6ba64dabc280b3e483a93f29df93688945b7f8fc/src/filter.rs#L4

If &buf isn't valid UTF-8, this results in undefined behaviour. Since filter is not marked as unsafe, it is currently possible to cause undefined behaviour by calling a safe function.

As far as I can tell, this buffer comes from a socket from outside the application, so it is in my opinion a better idea to use the safe str::from_utf8 with proper error handling instead.

gpluscb avatar May 17 '21 10:05 gpluscb