🔨」 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

@ -1,7 +1,7 @@
log_file = "test.log"
[server]
server_names = { "localhost", "2B5.local" }
# server_names = { "localhost", "2B5.local" }
host = "0.0.0.0"
port = 8080

View File

@ -67,6 +67,7 @@
nixd
nixfmt-rfc-style
norminette
siege
valgrind
git
gdb

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();

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/27 18:22:48 by adjoly #+# #+# */
/* Updated: 2025/05/30 15:48:16 by adjoly ### ########.fr */
/* Updated: 2025/05/30 16:30:40 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -62,10 +62,11 @@ void Server::_handle_client(size_t *i) {
if (PfdManager::getType(PfdManager::at(*i).fd)) {
if (PfdManager::at(*i).revents & POLLERR) {
_log->debug("pollerr");
close(PfdManager::at(*i).fd);
Client *client = _getClient(PfdManager::at(*i).fd);
_client_data.erase(
std::find(_client_data.begin(), _client_data.end(), client));
delete client;
PfdManager::remove(PfdManager::at(*i).fd);
delete _client_data[*i - _fds_server.size()];
_client_data.erase(_client_data.begin() + *i);
} else if (PfdManager::at(*i).revents & POLLIN) {
_log->debug("pollin");
Client *client = _getClient(PfdManager::at(*i).fd);
@ -133,7 +134,7 @@ void Server::_handle_resource(size_t i) {
if (!res->isProcessed() && res->isReady()) {
res->process();
// if (res->type() == CGI) {
_log->info("processingggg");
_log->info("processingggg");
// } else if (pfd.revents & res->event()) {
// res->process();
// _log->info("processingggg");

BIN
vgcore.78629 Normal file

Binary file not shown.

BIN
vgcore.80790 Normal file

Binary file not shown.