Skip to content

OS400: handle memory error in list conversion#3372

Closed
danielgustafsson wants to merge 1 commit intocurl:masterfrom
danielgustafsson:dg-os400_slist_convert
Closed

OS400: handle memory error in list conversion#3372
danielgustafsson wants to merge 1 commit intocurl:masterfrom
danielgustafsson:dg-os400_slist_convert

Conversation

@danielgustafsson
Copy link
Member

Curl_slist_append_nodup() returns NULL when it fails to create a new item for the specified list, and since the coding here reassigned the new list on top of the old list it would result in a dangling pointer
and lost memory. Also, in case we hit an allocation failure at some point during the conversion, with allocation succeeding again on the subsequent call(s) we will return a truncated list around the malloc
failure point.

Fix by assigning to a temporary list pointer, which can be checked (which is the common pattern for slist appending), and free all the resources on allocation failure.

Disclaimer: I have not tested this since I have no access to an OS400 environment.

Curl_slist_append_nodup() returns NULL when it fails to create a new
item for the specified list, and since the coding here reassigned the
new list on top of the old list it would result in a dangling pointer
and lost memory. Also, in case we hit an allocation failure at some
point during the conversion, with allocation succeeding again on the
subsequent call(s) we will return a truncated list around the malloc
failure point. Fix by assigning to a temporary list pointer, which can
be checked (which is the common pattern for slist appending), and free
all the resources on allocation failure.
@lock lock bot locked as resolved and limited conversation to collaborators Mar 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants