Skip to content

cgi_param_multiple() is broken, potentially causing endless loop in actual usage #37

Open

Description

@kennyk-peplink

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.

Activity

  1. kennyk-peplink commented on Jun 22, 2017

    @kennyk-peplink
    Author

    6691523

    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.

  2. kennyk-peplink commented on Jun 22, 2017

    @kennyk-peplink
    Author

    Suggested fix: Simply store the 'iterator', not the 'next iterator'; if there is a next fetch, start from that iterator's next.

    1. Replace "if (!iter) iter = formvars_start" with,
      iter = iter ? iter->next : formvars_start;

    2. Remove "iter = iter->next;" before break;

  3. added this to the milestone on Jun 22, 2017
  4. removed this from the v1.2.0 milestone on Jul 23, 2018
  5. LeSpocky commented on Jul 23, 2018

    @LeSpocky
    Collaborator

    Personally I have currently no usecase for cgi_param_multiple(), but I would be happy if you could provide a patch and a testcase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions