-
Notifications
You must be signed in to change notification settings - Fork 216
apr_buffer_cpy: return NULL on allocation failure to avoid undefined behaviour #73
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: trunk
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 |
|---|---|---|
|
|
@@ -297,6 +297,9 @@ APR_DECLARE(apr_buffer_t *) apr_buffer_cpy(apr_buffer_t *dst, | |
| apr_size_t size = src->size + src->zero_terminated; | ||
|
|
||
| void *mem = alloc(ctx, size); | ||
| if (!mem) { | ||
| return NULL; | ||
| } | ||
| memcpy(mem, src->d.mem, size); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation says nothing of what happens if alloc() returned NULL (compare with for example apr_buffer_arryadup where it is stated that the function will handle a NULL return from alloc()).
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated the A test exercising this path is also included. |
||
|
|
||
| dst->zero_terminated = src->zero_terminated; | ||
|
|
||
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.
Same comment as above.