Skip to content

Commit

Permalink
fix: Return Internal Server Error if Lua function has invalid return …
Browse files Browse the repository at this point in the history
…value.
  • Loading branch information
Benjamin Geer committed Dec 20, 2016
1 parent 87f1366 commit 2c72dde
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/SipiHttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ namespace Sipi {
//=========================================================================



static void iiif_send_info(Connection &conobj, SipiHttpServer *serv, shttps::LuaServer &luaserver, vector<string> &params, const string &imgroot, bool prefix_as_path) {
auto logger = Logger::getLogger(shttps::loggername);
conobj.setBuffer(); // we want buffered output, since we send JSON text...
Expand Down Expand Up @@ -240,18 +241,28 @@ namespace Sipi {
lval[2].value.s = cookie.c_str();

vector<LuaValstruct> rval;
rval = luaserver.executeLuafunction(&funcname, 3, lval);
try {
rval = luaserver.executeLuafunction(&funcname, 3, lval);
}
catch (shttps::Error err) {
send_error(conobj, Connection::INTERNAL_SERVER_ERROR, err.to_string());
return;
}

if (rval[0].type == LuaValstruct::STRING_TYPE) {
permission = rval[0].value.s;
}
else { ; // error handling!
else {
send_error(conobj, Connection::INTERNAL_SERVER_ERROR, "Lua function pre_flight must return two strings");
return;
}

if (rval[1].type == LuaValstruct::STRING_TYPE) {
infile = rval[1].value.s;
}
else { ; // error handling!
else {
send_error(conobj, Connection::INTERNAL_SERVER_ERROR, "Lua function pre_flight must return two strings");
return;
}

size_t pos = permission.find('=');
Expand Down Expand Up @@ -681,19 +692,29 @@ namespace Sipi {
lval[2].value.s = cookie;

vector<LuaValstruct> rval;
rval = luaserver.executeLuafunction(&funcname, 3, lval);
try {
rval = luaserver.executeLuafunction(&funcname, 3, lval);
}
catch (shttps::Error err) {
send_error(conobj, Connection::INTERNAL_SERVER_ERROR, err.to_string());
return;
}

if (rval[0].type == LuaValstruct::STRING_TYPE) {
permission = rval[0].value.s;
}
else { ; // error handling!
else {
send_error(conobj, Connection::INTERNAL_SERVER_ERROR, "Lua function pre_flight must return two strings");
return;
}

if (rval[1].type == LuaValstruct::STRING_TYPE) {
infile = rval[1].value.s;
}
else { ; // error handling!
}
else {
send_error(conobj, Connection::INTERNAL_SERVER_ERROR, "Lua function pre_flight must return two strings");
return;
}

size_t pos = permission.find(':');
string qualifier;
Expand Down

0 comments on commit 2c72dde

Please sign in to comment.