Skip to content

Commit

Permalink
fix leaks cgi path + seg fault dir listing /
Browse files Browse the repository at this point in the history
  • Loading branch information
terezamr committed May 23, 2024
1 parent cac2082 commit 1a39e43
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ server:
# * CGI extension exec. path map;
cgi:
.py: /usr/bin/python3
.php: /usr/bin/php
# .php: /usr/bin/php
# * Server routing;
route /main: # to do: HTTP redirect.
route /main: # to do: HTTP redirect.
root: /pages
index: index.html # default file to open if the request is the dir
dir_listing: off
Expand All @@ -32,7 +32,7 @@ server:
root: /srcs/conn
dir_listing: on
http_methods: GET
#index: a.cpp Res.cpp Req1.cpp
index: a.cpp Res.cpp Req1.cpp
route /up:
root: /uploads
dir_listing: on
Expand Down Expand Up @@ -61,7 +61,7 @@ server:
400: error/400.html
max_cbsize: 2000m
max_conn: 5
route /su:
route /s:
root: /srcs
dir_listing: on
http_methods: GET
Expand Down
5 changes: 3 additions & 2 deletions srcs/__utils/__file_manager_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ std::string FileManager::directory_listing(const std::string path, std::string r
DIR* dir = opendir(path.c_str());
std::stringstream ss;
std::string entry_path;

if (!dir)
throw HttpError("500", "Internal Server Error");
if (route_path.size() == 0)
route_path = "/";
if (route_path[route_path.size() - 1] != '/')
route_path += "/";
route_path += "/";
if (route_path[0] == '/')
route_path.erase(0, 1);
ss << "<meta name=\"referrer\" content=\"no-referrer\">";
Expand Down
4 changes: 3 additions & 1 deletion srcs/server_engine/ServerContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ ServerContext::ServerContext(t_server serverNode)

for (; cgi_it != serverNode.cgi.end(); cgi_it++)
{
if (!fopen(cgi_it->second.c_str(), "r"))
FILE* file = fopen(cgi_it->second.c_str(), "r");
if (!file)
throw ServerError("CGI path doesn't exist. Maybe the cgi is not installed");
fclose(file);
this->cgi_path.insert(std::make_pair(cgi_it->first, cgi_it->second));
}

Expand Down

0 comments on commit 1a39e43

Please sign in to comment.