Skip to content

Commit

Permalink
httpd: Properly handle missing body
Browse files Browse the repository at this point in the history
Return an internal server error instead of unconditionally use a NULL
body
  • Loading branch information
chouquette committed Aug 1, 2022
1 parent f5a4a03 commit c78826b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/network/httpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,20 @@ httpd_HandlerCallBack(httpd_callback_sys_t *p_sys, httpd_client_t *cl,
psz_remote_addr, NULL,
&answer->p_body, &answer->i_body);

if (!answer->p_body) {
const char* psz_result = "Internal Server Error";
char* psz_new;
if (asprintf(&psz_new, "HTTP/1.0 500 \r\n"
"Content-Length: %zu\r\n\r\n%s",
strlen(psz_result), psz_result) < 0)
answer->i_body = 0;
else
{
answer->p_body = (uint8_t*)psz_new;
answer->i_body = strlen((const char*)answer->p_body);
}
return VLC_SUCCESS;
}
if (query->i_type == HTTPD_MSG_HEAD) {
char *p = (char *)answer->p_body;

Expand Down

0 comments on commit c78826b

Please sign in to comment.