h2o / h2o/picohttpparser

SEGV on unknown address in picohttpparser/picohttpparser.c: line 204

Open
#89 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
2.1k
Forks
274
PR merge metrics
No merged PRs in 30d

Description

## version

latest

## crash description

Neither the function `phr_parse_request` nor the function `is_complete` validates the `buf` parameter: When parsing an HTTP request, if the input buffer pointer `buf` is `NULL`, the function does not correctly validate the pointer, which will lead to access to an illegal memory address and trigger a crash.

## crash position
```
static const char *is_complete(const char *buf, const char *buf_end, size_t last_len, int *ret)
{
int ret_cnt = 0;
buf = last_len < 3 ? buf : buf + last_len - 3;

while (1) {
CHECK_EOF();
if (*buf == '\015') { //crash
...
}}}
```

## poc
```
#include
#include
#include
#include

#include "picohttpparser.h"

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
const char *request = (const char *)data;
size_t request_length = size;
const char *method = NULL;
size_t method_len = 0;
const char *url = NULL;
size_t url_len = 0;
int version = 0;
struct phr_header headers[10];
size_t num_headers = 10;
size_t pos = 0;

int ret = phr_parse_request(request, request_length, &method, &method_len, &url, &url_len, &version, headers, &num_headers, &pos);

return 0;
}
```

## details
[crash_report](https://github.com/x-ray-z/crash_report/blob/main/crash_phr_parse_request.md)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in picohttpparser.c at is_complete and phr_parse_request, then reproduce the supplied fuzzing case and inspect the reported line 204. Confirm how a NULL buf reaches these functions, and consider the existing parser flow and available regression coverage; done means malformed input no longer accesses an illegal address and parsing behavior remains covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.