http-parser icon indicating copy to clipboard operation
http-parser copied to clipboard

http-parser impossible condition check

Open vinniefalco opened this issue 9 years ago • 2 comments

Consider this code (from http_parser.c):

            /* Transfer-Encoding: chunked */
            case h_matching_transfer_encoding_chunked:
              parser->index++;
              if (parser->index > sizeof(CHUNKED)-1
                  || c != CHUNKED[parser->index]) {
                h_state = h_general;
              } else if (parser->index == sizeof(CHUNKED)-2) {
                h_state = h_transfer_encoding_chunked;
              }
              break;

It seems parser->index > sizeof(CHUNKED)-1 can never be true, because if the token being checked matches, we would set h_state = h_transfer_encoding_chunked before parser->index can ever exceed sizeof(CHUNKED)-2. And if the token being checked doesn't match, then we will set h_state = h_general before parser->index can exceed sizeof(CHUNKED)-1.

I haven't actually tested this so I am not 100% sure.

vinniefalco avatar Jun 02 '16 08:06 vinniefalco

Yeah, it appears to be unreachable indeed. Would you care to open a PR to fix it?

indutny avatar Jun 14 '17 21:06 indutny

I haven't used the parser in a while so I am quite rusty, and I dont have a clone handy. It would probably do more harm than good at this point.

vinniefalco avatar Jun 14 '17 22:06 vinniefalco