+ in fill_script_path() : scipt_path and script_info are filled, removing leadin dot

+ in _cgi_pos() : check validity of extension if it's only alpha characters
+ severall pbm appears
This commit is contained in:
hugogogo
2022-08-13 14:38:50 +02:00
parent defb2ada61
commit 285f2d049f
8 changed files with 60 additions and 43 deletions

View File

@@ -1,13 +1,17 @@
#include "Webserv.hpp"
// TODO HUGO : go ameliorer la recherche comme on a dit.
// TODO HUGO : for the moment, this url valid a cgi, it shouldn't :
// http://localhost:4040/cgi-bin/cgi.phpp
// check the output for an alpha value maybe ? check rfc
size_t Webserv::_cgi_pos(Client *client, std::string &path)
{
std::vector<std::string> v_ext;
std::vector<std::string>::const_iterator it;
std::vector<std::string>::const_iterator it_end;
size_t pos = 0;
size_t len;
std::locale loc; // for isalpha()
/*DEBUG*/ it = client->assigned_location->cgi_ext.begin(); std::cout << B_YELLOW << "\nDEBUG _cgi_pos()\n" << RESET << "vector_ext.size():[" << client->assigned_location->cgi_ext.size() << "]\n\n";
v_ext = client->assigned_location->cgi_ext;
if (v_ext.empty())
@@ -23,8 +27,10 @@ size_t Webserv::_cgi_pos(Client *client, std::string &path)
it = client->assigned_location->cgi_ext.begin();
for ( ; it != it_end; ++it)
{ /*DEBUG*/ std::cout << " for\n"; std::cout << " &path[pos]:[" << &path[pos] << "]\n" << " *it:[" << *it << "]\n" << " (*it).size():[" << (*it).size() << "]\n" << " path.substr(pos, (*it).size()):[" << path.substr(pos + 1, (*it).size()) << "]\n\n";
if (path.compare(pos + 1, (*it).size(), *it) == 0)
return pos;
len = (*it).size();
if (path.compare(pos + 1, len, *it) == 0)
if ( !std::isalpha(path[pos + 1 + len], loc) )
return pos + 1 + len;
}
pos++;
}
@@ -111,6 +117,7 @@ std::string Webserv::_exec_script(Client *client, char **env)
int fd_out[2];
int save_in = dup(STDIN_FILENO);
int save_out = dup(STDOUT_FILENO);
std::string path;
pipe(fd_in);
pipe(fd_out);
@@ -123,10 +130,10 @@ std::string Webserv::_exec_script(Client *client, char **env)
close(FD_WR_TO_CHLD);
close(FD_RD_FR_CHLD);
dup2(FD_RD_FR_PRNT, STDIN_FILENO);
dup2(FD_WR_TO_PRNT, STDOUT_FILENO);
// DEBUG
std::cerr << "execve:\n";
execve(client->get_rq_script_path().c_str(), nll, env);
dup2(FD_WR_TO_PRNT, STDOUT_FILENO); /*DEBUG*/std::cerr << "execve:\n";
path = "." + client->get_rq_script_path();
execve(path.c_str(), nll, env);
// for tests execve crash :
//execve("wrong", nll, env);
std::cerr << "execve crashed.\n";