🔨」 fix: fixed invalid read that caused crash when pollerr

This commit is contained in:
2025-05-30 16:36:07 +02:00
parent f0a5ceb397
commit ad19276667
6 changed files with 22 additions and 13 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/30 09:40:16 by adjoly #+# #+# */
/* Updated: 2025/05/30 16:20:15 by adjoly ### ########.fr */
/* Updated: 2025/05/30 16:22:24 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -34,10 +34,7 @@ Get::Get(std::string &data, config::Server *srv) {
this->parse(data);
}
Get::~Get(void) {
// if (_url != not_nullptr)
// delete _url;
}
Get::~Get(void) {}
void Get::parse(std::string const &data) {
std::istringstream stream(data);
@ -142,6 +139,8 @@ Response Get::execute(void) {
server::PfdManager::remove(_cgi->getId());
server::ResourceManager::remove(_cgi->getId());
_cgi = not_nullptr;
if (_url != not_nullptr)
delete _url;
return response;
}
std::string str = static_cast<server::Cgi *>(_cgi)->str();
@ -150,6 +149,8 @@ Response Get::execute(void) {
server::PfdManager::remove(_cgi->getId());
server::ResourceManager::remove(_cgi->getId());
_cgi = not_nullptr;
if (_url != not_nullptr)
delete _url;
return response;
}
@ -180,8 +181,11 @@ Response Get::execute(void) {
struct stat file_stat;
std::vector<std::string> files;
if ((dir = opendir(this->_target.c_str())) == NULL)
if ((dir = opendir(this->_target.c_str())) == NULL) {
if (_url != not_nullptr)
delete _url;
throw;
}
while ((entry = readdir(dir)) != NULL) {
std::string file_name = entry->d_name;
if (file_name == ".")
@ -235,8 +239,11 @@ body {\n\
response.addHeader("Content-Length", length.str());
response.addHeader("Content-Type", "text/html");
response.setBody(body);
} else
} else {
if (_url != not_nullptr)
delete _url;
throw std::runtime_error("dir but no dirlist");
}
} else {
std::ifstream file(this->_target.c_str(), std::ios::binary);
std::streampos file_start = file.tellg();