diff --git a/src/http/cgi/execute.cpp b/src/http/cgi/execute.cpp index 289139f..d261320 100644 --- a/src/http/cgi/execute.cpp +++ b/src/http/cgi/execute.cpp @@ -106,8 +106,14 @@ HttpResponse CgiHandler::execute(const HttpRequest& request, const LocationConfi int stdinPipe[2]; int stdoutPipe[2]; - if (pipe(stdinPipe) == -1 || pipe(stdoutPipe) == -1) + if (pipe(stdinPipe) == -1) return buildHttpError(500, "Internal Server Error"); + if (pipe(stdoutPipe) == -1) + { + close(stdinPipe[0]); + close(stdinPipe[1]); + return buildHttpError(500, "Internal Server Error"); + } pid_t childPid = fork(); if (childPid == -1) @@ -118,7 +124,7 @@ HttpResponse CgiHandler::execute(const HttpRequest& request, const LocationConfi } if (childPid == 0) - runChildProcess(interpreter, scriptPath, argv, envPointers.data(), stdinPipe, stdoutPipe); + runChildProcess(interpreter, scriptPath, argv, &envPointers[0], stdinPipe, stdoutPipe); close(stdinPipe[0]); close(stdoutPipe[1]); diff --git a/src/http/handlers/GetHandler.cpp b/src/http/handlers/GetHandler.cpp index 13a05c9..0b855d4 100644 --- a/src/http/handlers/GetHandler.cpp +++ b/src/http/handlers/GetHandler.cpp @@ -10,12 +10,7 @@ static HttpResponse buildAutoindex(const std::string& directoryPath, const std:: { DIR* directory = opendir(directoryPath.c_str()); if (!directory) - { - HttpResponse response; - response.status_code = 403; - response.status_msg = "Forbidden"; - return response; - } + return buildHttpError(403, "Forbidden"); std::string listingHtml = "

Index of " + requestUri + "