mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-05 17:30:27 +00:00
Add check to ServeRedirect to ensure valid location
This commit is contained in:
parent
275be556cd
commit
b7a40bd737
1 changed files with 8 additions and 5 deletions
|
@ -3061,25 +3061,28 @@ static int LuaServeIndex(lua_State *L) {
|
|||
|
||||
static int LuaServeRedirect(lua_State *L) {
|
||||
size_t loclen;
|
||||
const char *location;
|
||||
const char *location, *eval;
|
||||
int code;
|
||||
OnlyCallDuringRequest("ServeRedirect");
|
||||
|
||||
code = luaL_checkinteger(L, 1);
|
||||
if (!(300 <= code && code <= 399)) {
|
||||
luaL_argerror(L, 1, "bad status code for redirect");
|
||||
luaL_argerror(L, 1, "bad status code");
|
||||
unreachable;
|
||||
}
|
||||
location = luaL_checklstring(L, 2, &loclen);
|
||||
|
||||
if (msg.version < 10) {
|
||||
(void)ServeError(505, "HTTP Version Not Supported");
|
||||
lua_pushboolean(L, false);
|
||||
} else {
|
||||
if (!(eval = EncodeHttpHeaderValue(location, loclen, 0))) {
|
||||
luaL_argerror(L, 2, "invalid location");
|
||||
unreachable;
|
||||
}
|
||||
LOGF("REDIRECT %d to %s", code, location);
|
||||
luaheaderp = AppendHeader(
|
||||
SetStatus(code, GetHttpReason(code)), "Location",
|
||||
FreeLater(EncodeHttpHeaderValue(location, loclen, 0)));
|
||||
SetStatus(code, GetHttpReason(code)), "Location", eval);
|
||||
free(eval);
|
||||
lua_pushboolean(L, true);
|
||||
}
|
||||
return 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue