From 8ff2716345ea32697c870cc57ecace6a5bd5f794 Mon Sep 17 00:00:00 2001 From: byronlove111 Date: Wed, 17 Jun 2026 16:29:37 +0200 Subject: [PATCH] fix(cpp98): replace vector::data() with &v[0], fix pipe fd leak, fix buildAutoindex 403 - execute.cpp: envPointers.data() -> &envPointers[0] (data() est C++11 sur vector) - execute.cpp: ferme stdinPipe si le second pipe() echoue (fd leak) - GetHandler.cpp: buildAutoindex erreur 403 -> buildHttpError (headers manquants) Co-authored-by: Cursor --- src/http/cgi/execute.cpp | 10 ++++++++-- src/http/handlers/GetHandler.cpp | 7 +------ 2 files changed, 9 insertions(+), 8 deletions(-) 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 + "