cgi_param_multiple() is broken, potentially causing endless loop in actual usage
It's typical (if not only) use case:
while ((value = cgi_param_multiple(name)) != NULL) { // processing here... }
will cause endless loop when name is found at the end of the CGI parameter list.
https://github.com/rafaelsteil/libcgi/commit/66915238b0236055164ee2bab3910b8d87493f7d
Currently cgi_param_multiple() stored the "next iterator" for repeated usage. When the last CGI parameter is match and fetched, however, we've got a value and "next iteration" is NULL; subsequently call will redo a fetching from the start, falling into endless loop.
Suggested fix: Simply store the 'iterator', not the 'next iterator'; if there is a next fetch, start from that iterator's next.
-
Replace "if (!iter) iter = formvars_start" with, iter = iter ? iter->next : formvars_start;
-
Remove "iter = iter->next;" before break;
Personally I have currently no usecase for cgi_param_multiple(), but I would be happy if you could provide a patch and a testcase.