[vlc-commits] [Git][videolan/vlc][master] 2 commits: lua: httpd: Return a valid body in case of errors
Hugo Beauzée-Luyssen (@chouquette)
gitlab at videolan.org
Mon Aug 1 14:20:47 UTC 2022
Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC
Commits:
f5a4a03e by Hugo Beauzée-Luyssen at 2022-08-01T14:06:31+00:00
lua: httpd: Return a valid body in case of errors
The body is used unconditionally from the callsite
- - - - -
c78826ba by Hugo Beauzée-Luyssen at 2022-08-01T14:06:31+00:00
httpd: Properly handle missing body
Return an internal server error instead of unconditionally use a NULL
body
- - - - -
2 changed files:
- modules/lua/libs/httpd.c
- src/network/httpd.c
Changes:
=====================================
modules/lua/libs/httpd.c
=====================================
@@ -155,6 +155,15 @@ static int vlclua_httpd_handler_callback(
const char *psz_err = lua_tostring( L, -1 );
msg_Err( p_this, "Error while running the lua HTTPd handler "
"callback: %s", psz_err );
+ char* psz_new;
+ if (asprintf(&psz_new, "Status: 500\n"
+ "Content-Length: %zu\n\n%s", strlen(psz_err), psz_err) < 0)
+ *pi_data = 0;
+ else
+ {
+ *pp_data = (uint8_t*)psz_new;
+ *pi_data = strlen(psz_new);
+ }
lua_settop( L, 2 );
/* function data */
return VLC_EGENERIC;
=====================================
src/network/httpd.c
=====================================
@@ -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;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e40112f175356227d7baa484c80e9c679cc9f110...c78826ba4499677e5bc7b6f3d57c733284e31afa
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e40112f175356227d7baa484c80e9c679cc9f110...c78826ba4499677e5bc7b6f3d57c733284e31afa
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list