Skip to content

Commit ed09c66

Browse files
stackiaclaude
andcommitted
fix: prevent NULL pointer crash when r2h-token is not configured
Add NULL pointer checks for config.r2h_token before dereferencing in http.c and http_proxy.c. config.r2h_token is a pointer that can be NULL when the -T option is not provided, so checking config.r2h_token[0] directly would crash with a segfault. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6bc8964 commit ed09c66

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

src/http.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ int http_parse_request(char *inbuf, int *in_len, http_request_t *req) {
275275
char filter_buf[2048];
276276

277277
/* Filter r2h-token from Cookie header */
278-
if (strcasecmp(inbuf, "Cookie") == 0 && config.r2h_token[0]) {
278+
if (strcasecmp(inbuf, "Cookie") == 0 && config.r2h_token &&
279+
config.r2h_token[0] != '\0') {
279280
int flen = http_filter_cookie(value, "r2h-token", filter_buf,
280281
sizeof(filter_buf));
281282
if (flen > 0) {
@@ -286,7 +287,8 @@ int http_parse_request(char *inbuf, int *in_len, http_request_t *req) {
286287
}
287288
}
288289
/* Filter R2HTOKEN/xxx from User-Agent header */
289-
else if (strcasecmp(inbuf, "User-Agent") == 0 && config.r2h_token[0]) {
290+
else if (strcasecmp(inbuf, "User-Agent") == 0 && config.r2h_token &&
291+
config.r2h_token[0] != '\0') {
290292
int flen = http_filter_user_agent_token(value, filter_buf,
291293
sizeof(filter_buf));
292294
if (flen > 0) {

src/http_proxy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ int http_proxy_parse_url(http_proxy_session_t *session, const char *url) {
151151

152152
/* Check if URL has query string with potential r2h-token */
153153
const char *query_start = strchr(slash, '?');
154-
if (query_start && config.r2h_token[0]) {
154+
if (query_start && config.r2h_token && config.r2h_token[0] != '\0') {
155155
/* Copy path portion up to query string */
156156
size_t path_len = (size_t)(query_start - slash);
157157
memcpy(session->target_path, slash, path_len);

0 commit comments

Comments
 (0)