Skip to content
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

segfault in slist_item() when value is NULL #31

Closed
LeSpocky opened this issue May 18, 2016 · 1 comment · Fixed by #32
Closed

segfault in slist_item() when value is NULL #31

LeSpocky opened this issue May 18, 2016 · 1 comment · Fixed by #32
Labels
Milestone

Comments

@LeSpocky
Copy link
Collaborator

In slist_add() there's no check on the contents of item->name or item->value so items with name or value set to NULL can be added to the list.

The functions slist_delete() and slist_item() access item->name which would cause a segfault if name is set to NULL.

Additionally in slist_item() also item->value is accessed and can be NULL, here:

return (!begin->value[0] ? NULL : begin->value);

While libcgi does not add items with empty names by itself, it may add items with empty values. For example on POST requests with empty text boxes a QUERY_STRING can be like this:

foo=&bar=baz

The segfault happens in the above mentioned line in slist_item(), if the list is then accessed via cgi_param( "foo" ) 💥

I suggest we allow the value to be set to NULL and return NULL in slist_item() in this case.

The question remains if we should also allow adding items with empty name in slist_add(), but that's subject of another topic. 😉

@LeSpocky LeSpocky added the bug label May 18, 2016
@LeSpocky LeSpocky added this to the v1.1.1 milestone May 18, 2016
@LeSpocky
Copy link
Collaborator Author

Currently slist_item() returns NULL on an empty string aka if the first byte of item->value is the null termination of the string. People maybe rely on this, so we should not break it, although it would be possible and maybe more intuitive to return a pointer to the empty string.

LeSpocky added a commit to LeSpocky/libcgi that referenced this issue May 18, 2016
fixes rafaelsteil#31

Signed-off-by: Alexander Dahl <[email protected]>
LeSpocky added a commit to LeSpocky/libcgi that referenced this issue Feb 24, 2017
fixes rafaelsteil#31

Signed-off-by: Alexander Dahl <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant