mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-06-25 09:33:36 +02:00
「🔨」 fix: fixed invalid read that caused crash when pollerr
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
log_file = "test.log"
|
log_file = "test.log"
|
||||||
|
|
||||||
[server]
|
[server]
|
||||||
server_names = { "localhost", "2B5.local" }
|
# server_names = { "localhost", "2B5.local" }
|
||||||
host = "0.0.0.0"
|
host = "0.0.0.0"
|
||||||
port = 8080
|
port = 8080
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@
|
|||||||
nixd
|
nixd
|
||||||
nixfmt-rfc-style
|
nixfmt-rfc-style
|
||||||
norminette
|
norminette
|
||||||
|
siege
|
||||||
valgrind
|
valgrind
|
||||||
git
|
git
|
||||||
gdb
|
gdb
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/30 09:40:16 by adjoly #+# #+# */
|
/* 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);
|
this->parse(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
Get::~Get(void) {
|
Get::~Get(void) {}
|
||||||
// if (_url != not_nullptr)
|
|
||||||
// delete _url;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Get::parse(std::string const &data) {
|
void Get::parse(std::string const &data) {
|
||||||
std::istringstream stream(data);
|
std::istringstream stream(data);
|
||||||
@ -142,6 +139,8 @@ Response Get::execute(void) {
|
|||||||
server::PfdManager::remove(_cgi->getId());
|
server::PfdManager::remove(_cgi->getId());
|
||||||
server::ResourceManager::remove(_cgi->getId());
|
server::ResourceManager::remove(_cgi->getId());
|
||||||
_cgi = not_nullptr;
|
_cgi = not_nullptr;
|
||||||
|
if (_url != not_nullptr)
|
||||||
|
delete _url;
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
std::string str = static_cast<server::Cgi *>(_cgi)->str();
|
std::string str = static_cast<server::Cgi *>(_cgi)->str();
|
||||||
@ -150,6 +149,8 @@ Response Get::execute(void) {
|
|||||||
server::PfdManager::remove(_cgi->getId());
|
server::PfdManager::remove(_cgi->getId());
|
||||||
server::ResourceManager::remove(_cgi->getId());
|
server::ResourceManager::remove(_cgi->getId());
|
||||||
_cgi = not_nullptr;
|
_cgi = not_nullptr;
|
||||||
|
if (_url != not_nullptr)
|
||||||
|
delete _url;
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,8 +181,11 @@ Response Get::execute(void) {
|
|||||||
struct stat file_stat;
|
struct stat file_stat;
|
||||||
std::vector<std::string> files;
|
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;
|
throw;
|
||||||
|
}
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
std::string file_name = entry->d_name;
|
std::string file_name = entry->d_name;
|
||||||
if (file_name == ".")
|
if (file_name == ".")
|
||||||
@ -235,8 +239,11 @@ body {\n\
|
|||||||
response.addHeader("Content-Length", length.str());
|
response.addHeader("Content-Length", length.str());
|
||||||
response.addHeader("Content-Type", "text/html");
|
response.addHeader("Content-Type", "text/html");
|
||||||
response.setBody(body);
|
response.setBody(body);
|
||||||
} else
|
} else {
|
||||||
|
if (_url != not_nullptr)
|
||||||
|
delete _url;
|
||||||
throw std::runtime_error("dir but no dirlist");
|
throw std::runtime_error("dir but no dirlist");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
std::ifstream file(this->_target.c_str(), std::ios::binary);
|
std::ifstream file(this->_target.c_str(), std::ios::binary);
|
||||||
std::streampos file_start = file.tellg();
|
std::streampos file_start = file.tellg();
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/27 18:22:48 by adjoly #+# #+# */
|
/* 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::getType(PfdManager::at(*i).fd)) {
|
||||||
if (PfdManager::at(*i).revents & POLLERR) {
|
if (PfdManager::at(*i).revents & POLLERR) {
|
||||||
_log->debug("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);
|
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) {
|
} else if (PfdManager::at(*i).revents & POLLIN) {
|
||||||
_log->debug("pollin");
|
_log->debug("pollin");
|
||||||
Client *client = _getClient(PfdManager::at(*i).fd);
|
Client *client = _getClient(PfdManager::at(*i).fd);
|
||||||
@ -133,7 +134,7 @@ void Server::_handle_resource(size_t i) {
|
|||||||
if (!res->isProcessed() && res->isReady()) {
|
if (!res->isProcessed() && res->isReady()) {
|
||||||
res->process();
|
res->process();
|
||||||
// if (res->type() == CGI) {
|
// if (res->type() == CGI) {
|
||||||
_log->info("processingggg");
|
_log->info("processingggg");
|
||||||
// } else if (pfd.revents & res->event()) {
|
// } else if (pfd.revents & res->event()) {
|
||||||
// res->process();
|
// res->process();
|
||||||
// _log->info("processingggg");
|
// _log->info("processingggg");
|
||||||
|
BIN
vgcore.78629
Normal file
BIN
vgcore.78629
Normal file
Binary file not shown.
BIN
vgcore.80790
Normal file
BIN
vgcore.80790
Normal file
Binary file not shown.
Reference in New Issue
Block a user