-
Notifications
You must be signed in to change notification settings - Fork 2
Guard val_mem_copy against buffer overflow #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -632,7 +632,7 @@ uint32_t val_printf(print_verbosity_t verbosity, const char *msg, ...) | |
|
|
||
| if (len > 0 && msg[len - 1] == '\n') | ||
| { | ||
| val_mem_copy(formatted_msg, msg, len - 1); | ||
| val_mem_copy(formatted_msg, sizeof(formatted_msg), msg, len - 1); | ||
| formatted_msg[len - 1] = '\r'; | ||
| formatted_msg[len] = '\n'; | ||
| formatted_msg[len + 1] = '\0'; | ||
|
Comment on lines
+635
to
638
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clamping logic should account for null termination. When
lenequalsdest_size, the code will write up to the last byte of the destination buffer, leaving no room for a null terminator if one is expected. Consider clamping todest_size - 1if the destination is intended to be a null-terminated string, or document that this function does not null-terminate.