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

slist: fix possible segfaults #32

Merged
merged 1 commit into from
Feb 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/list.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
LibCGI - A library to make CGI programs using C
Copyright (C) 2001 Rafael Steil
Copyright 2016 Alexander Dahl <[email protected]>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -102,14 +103,20 @@ int slist_delete(char *name, formvars **start, formvars **last)
// Returns the value of the item pointed by name
char *slist_item(const char *name, formvars *start)
{
formvars *begin;
begin = start;
formvars *curr = start;

while (begin) {
if (!strcasecmp(begin->name, name))
return (!begin->value[0] ? NULL : begin->value);
if ( !name ) return NULL;

begin = begin->next;
while ( curr ) {
if ( !strcasecmp( curr->name, name ) ) {
if ( curr->value == NULL || curr->value[0] == '\0' ) {
return NULL;
} else {
return curr->value;
}
}

curr = curr->next;
}

return NULL;
Expand Down