leaks and invalid read size fixed, commande kick with argument comment fixed

This commit is contained in:
Samy Ben Tayeb 2025-06-23 15:29:48 +02:00
parent 2023ffa75e
commit 92986bf0f9
5 changed files with 23 additions and 21 deletions

View file

@ -6,7 +6,7 @@
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */ /* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/20 21:57:49 by rparodi #+# #+# */ /* Created: 2025/05/20 21:57:49 by rparodi #+# #+# */
/* Updated: 2025/06/21 14:38:06 by sben-tay ### ########.fr */ /* Updated: 2025/06/23 14:55:06 by sben-tay ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -39,7 +39,6 @@ class User
public: public:
User(short unsigned fd, PollManager& poll); User(short unsigned fd, PollManager& poll);
User( void ); // default constructor for bot service
short unsigned int getFd() const; short unsigned int getFd() const;
void appendToReadBuffer(const std::string &data); void appendToReadBuffer(const std::string &data);
void appendToWriteBuffer(const std::string &data); void appendToWriteBuffer(const std::string &data);

View file

@ -6,7 +6,7 @@
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */ /* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/20 22:43:24 by rparodi #+# #+# */ /* Created: 2025/05/20 22:43:24 by rparodi #+# #+# */
/* Updated: 2025/06/21 19:04:34 by sben-tay ### ########.fr */ /* Updated: 2025/06/23 14:55:34 by sben-tay ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -25,11 +25,6 @@ Channel::Channel(const std::string &name, User *owner, size_t maxUsers, bool nee
} }
Channel::~Channel() { Channel::~Channel() {
for (std::list<User *>::iterator it = _users.begin(); it != _users.end(); ++it) {
if (*it != _owner) {
delete *it;
}
}
_users.clear(); _users.clear();
_operators.clear(); _operators.clear();
_invited.clear(); _invited.clear();

View file

@ -6,7 +6,7 @@
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */ /* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
/* Updated: 2025/06/20 16:57:53 by rparodi ### ########.fr */ /* Updated: 2025/06/23 15:01:35 by sben-tay ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,13 +22,13 @@ e_code Invite::checkArgs() {
this->_sender->appendToWriteBuffer(msg461); this->_sender->appendToWriteBuffer(msg461);
return ERR_NEEDMOREPARAMS; return ERR_NEEDMOREPARAMS;
} }
if (_args.at(1).at(0) != '#') { if (_args.at(2).at(0) != '#') {
WARNING_MSG("Invalid channel name for INVITE command"); WARNING_MSG("Invalid channel name for INVITE command");
INFO_MSG("Channel names must start with a '#' character"); INFO_MSG("Channel names must start with a '#' character");
return ERR_NOSUCHCHANNEL; return ERR_NOSUCHCHANNEL;
} else } else
_args.at(1).erase(0, 1); _args.at(2).erase(0, 1);
_cTarget = searchList(_server->getChannelsList(), _args.at(1)); _cTarget = searchList(_server->getChannelsList(), _args.at(2));
if (_cTarget == NULL) { if (_cTarget == NULL) {
WARNING_MSG("Channel not found for INVITE command"); WARNING_MSG("Channel not found for INVITE command");
INFO_MSG("You can only invite users to channels you are in"); INFO_MSG("You can only invite users to channels you are in");
@ -38,7 +38,7 @@ e_code Invite::checkArgs() {
WARNING_MSG("You are not an operator in the channel for INVITE command"); WARNING_MSG("You are not an operator in the channel for INVITE command");
return ERR_NOPRIVILEGES; return ERR_NOPRIVILEGES;
} }
_uTarget = searchList(this->_users, _args.at(2)); _uTarget = searchList(this->_users, _args.at(1));
if (this->_uTarget == NULL) { if (this->_uTarget == NULL) {
WARNING_MSG("User not found"); WARNING_MSG("User not found");
return ERR_NOSUCHNICK; return ERR_NOSUCHNICK;

View file

@ -6,7 +6,7 @@
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */ /* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
/* Updated: 2025/06/22 19:38:09 by sben-tay ### ########.fr */ /* Updated: 2025/06/23 15:27:38 by sben-tay ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -68,7 +68,7 @@ void Kick::execute() {
if (BONUS && _args.at(2) == "bot") { if (BONUS && _args.at(2) == "bot") {
if (_cTarget->getBotChannel()) { if (_cTarget->getBotChannel()) {
std::string msgKickBot = ":bot!ircbot@localhost KICK #" + _cTarget->getName() + " " + "bot"; std::string msgKickBot = ":bot!ircbot@localhost KICK #" + _cTarget->getName() + " " + "bot";
if (_args.size() > 4) if (_args.size() > 3)
msgKickBot += " :" + _args.at(3); msgKickBot += " :" + _args.at(3);
msgKickBot += "\r\n"; msgKickBot += "\r\n";
std::cout << " msgKickBot: " << msgKickBot << std::endl; std::cout << " msgKickBot: " << msgKickBot << std::endl;
@ -80,9 +80,12 @@ void Kick::execute() {
std::string msgPart = ":" + this->_uTarget->getPrefix() + " PART #" + _cTarget->getName() + "\r\n"; std::string msgPart = ":" + this->_uTarget->getPrefix() + " PART #" + _cTarget->getName() + "\r\n";
std::string msgKick = ":" + this->_uTarget->getPrefix() + " KICK #" + this->_cTarget->getName(); std::string msgKick = ":" + this->_uTarget->getPrefix() + " KICK #" + this->_cTarget->getName() + " " + _uTarget->getName();
if (_args.size() > 4) if (_args.size() > 3)
msgKick += " :" + _args.at(4); {
DEBUG_MSG("Je rajoute le message de kick avec un motif");
msgKick += " :" + _args.at(3);
}
msgKick += "\r\n"; msgKick += "\r\n";
std::cout << " msgKick: " << msgKick << "msgPart: " << msgPart << std::endl; std::cout << " msgKick: " << msgKick << "msgPart: " << msgPart << std::endl;

View file

@ -6,7 +6,7 @@
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */ /* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/13 11:11:07 by rparodi #+# #+# */ /* Created: 2025/05/13 11:11:07 by rparodi #+# #+# */
/* Updated: 2025/06/23 14:39:03 by sben-tay ### ########.fr */ /* Updated: 2025/06/23 14:46:53 by sben-tay ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -52,10 +52,15 @@ Server::Server(int port, const std::string &password) : _port(port), _password(p
Server::~Server() Server::~Server()
{ {
std::cout << CLR_GREY << "Info: Server destructor called" << CLR_RESET << std::endl; std::cout << CLR_GREY << "Info: Server destructor called" << CLR_RESET << std::endl;
if (_serverFd != -1) if (_serverFd != -1) {
{
close(_serverFd); close(_serverFd);
} }
for (std::list<Channel *>::iterator it = _channels.begin(); it != _channels.end(); ++it) {
delete *it;
}
for (std::map<int, User *>::iterator it = _users.begin(); it != _users.end(); ++it) {
delete it->second;
}
} }
std::vector<std::string> splitLines(const std::string& input); std::vector<std::string> splitLines(const std::string& input);