You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RCUTILS_SAFE_FWRITE_TO_STDERR with variable length messages #78
From what I can tell the count passed to fwrite is not a max size, but the size, so I think this line can cause buffer overrun if the msg is less than length 8. That doesn't happen with our existing code because they're all longer (instead our messages get truncated), but it could happen.
What's the appropriate fix here?
continue using sizeof(msg) and only use this macro with static buffers
switch to strlen(msg) and only use this macro will null-terminated buffers (also a risk)
Ouch. I don't think we can stick with sizeof(msg) here; there is just way too much risk that someone will pass an allocated pointer to it (and there isn't really a good way to enforce that restriction at compile-time). While strlen(msg) is always a risk, it is a risk you have to take when using C, so I'd suggest we go with that.
To double check my understanding: strnlen_s with a large number doesn't remove the chance of buffer overrun, it's just that overrun length will have an upper bound, yeah?
Activity
Avoid use of RCUTILS_SAFE_FWRITE_TO_STDERR with dynamic buffer
clalancette commentedon Dec 1, 2017
Ouch. I don't think we can stick with
sizeof(msg)here; there is just way too much risk that someone will pass an allocated pointer to it (and there isn't really a good way to enforce that restriction at compile-time). Whilestrlen(msg)is always a risk, it is a risk you have to take when using C, so I'd suggest we go with that.wjwwood commentedon Dec 1, 2017
You can use
strnlen_swith a relatively large bound to prevent a really malicious case:http://en.cppreference.com/w/c/string/byte/strlen
clalancette commentedon Dec 1, 2017
Oh, nice, I didn't know about that. That sounds like a good thing to use.
dhood commentedon Dec 1, 2017
To double check my understanding:
strnlen_swith a large number doesn't remove the chance of buffer overrun, it's just that overrun length will have an upper bound, yeah?wjwwood commentedon Dec 1, 2017
Yeah.
Use strlen / strnlen_s in RCUTILS_SAFE_FWRITE_TO_STDERR
Use strlen / strnlen_s in RCUTILS_SAFE_FWRITE_TO_STDERR
Use strlen / strnlen_s in RCUTILS_SAFE_FWRITE_TO_STDERR (#80)