-
Notifications
You must be signed in to change notification settings - Fork 119
RCUTILS_SAFE_FWRITE_TO_STDERR with variable length messages #78
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't workingquestionFurther information is requestedFurther information is requested
Description
If you pass a message of type const char * to RCUTILS_SAFE_FWRITE_TO_STDERR e.g.
Line 116 in 954ae9b
| RCUTILS_SAFE_FWRITE_TO_STDERR(rcutils_get_error_string_safe()); |
then the sizeof(msg) calculation in the macro gives the size of the pointer:
rcutils/include/rcutils/error_handling.h
Line 44 in 954ae9b
| #define RCUTILS_SAFE_FWRITE_TO_STDERR(msg) fwrite(msg, sizeof(char), sizeof(msg), stderr) |
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)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingquestionFurther information is requestedFurther information is requested