taiscremaschi / 42_Irc

2 stars 2 forks source link

61 fix program for scripts #62

Open taiscremaschi opened 3 months ago

taiscremaschi commented 3 months ago

alterei o nosso server dar split no começo de \n. isso faz ele entrar na nossa funcao principal de maneira mais segura. agr o findcmd n tem for looping pq os indices sao definidos bem...

paulasbia commented 3 months ago

Leaks on test 01

  1. Start our server
  2. Start a nc user with the wrong user and press Enter 3 times:
PASS 123
NICK pab
USER wrong

We have seg. fault if wrong PASS attempt to:

PASS wrong

(This does not occur on the main branch)

==1023956== Memcheck, a memory error detector ==1023956== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==1023956== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info ==1023956== Command: ./ircserv 8081 123 ==1023956== Parent PID: 1023938 ==1023956== ==1023956== Invalid read of size 8 ==1023956== at 0x49BCBA4: std::cxx11::basic_string<char, std::char_traits, std::allocator >::compare(char const*) const (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30) ==1023956== by 0x118127: bool std::operator==<char, std::char_traits, std::allocator >(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, char const) (basic_string.h:6250) ==1023956== by 0x116A7A: ServerManager::findCmd(std::vector<std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::cxx11::basic_string<char, std::char_traits, std::allocator > > > const&, Client&, IrcMessages&, std::cxx11::basic_string<char, std::char_traits, std::allocator >) (ServerManager.cpp:470) ==1023956== by 0x11791B: ServerManager::handleIrcCmds(std::cxx11::basic_string<char, std::char_traits, std::allocator >, int, std::cxx11::basic_string<char, std::char_traits, std::allocator >) (ServerManager.cpp:546) ==1023956== by 0x10C433: Server::runServer() (Server.cpp:111) ==1023956== by 0x10C83D: Server::inicializeServer() (Server.cpp:164) ==1023956== by 0x10BAF0: main (main.cpp:29) ==1023956== Address 0x8 is not stack'd, malloc'd or (recently) free'd ==1023956== ==1023956== ==1023956== Process terminating with default action of signal 11 (SIGSEGV) ==1023956== Access not within mapped region at address 0x8 ==1023956== at 0x49BCBA4: std::cxx11::basic_string<char, std::char_traits, std::allocator >::compare(char const) const (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30) ==1023956== by 0x118127: bool std::operator==<char, std::char_traits, std::allocator >(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, char const*) (basic_string.h:6250) ==1023956== by 0x116A7A: ServerManager::findCmd(std::vector<std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::cxx11::basic_string<char, std::char_traits, std::allocator > > > const&, Client&, IrcMessages&, std::cxx11::basic_string<char, std::char_traits, std::allocator >) (ServerManager.cpp:470) ==1023956== by 0x11791B: ServerManager::handleIrcCmds(std::cxx11::basic_string<char, std::char_traits, std::allocator >, int, std::__cxx11::basic_string<char, std::char_traits, std::allocator >) (ServerManager.cpp:546) ==1023956== by 0x10C433: Server::runServer() (Server.cpp:111) ==1023956== by 0x10C83D: Server::inicializeServer() (Server.cpp:164) ==1023956== by 0x10BAF0: main (main.cpp:29) ==1023956== If you believe this happened as a result of a stack ==1023956== overflow in your program's main thread (unlikely but ==1023956== possible), you can try to increase the size of the ==1023956== main thread stack using the --main-stacksize= flag. ==1023956== The main thread stack size used in this run was 8388608. ==1023956== ==1023956== HEAP SUMMARY: ==1023956== in use at exit: 74,157 bytes in 8 blocks ==1023956== total heap usage: 65 allocs, 57 frees, 77,500 bytes allocated ==1023956== ==1023956== 16 bytes in 1 blocks are still reachable in loss record 1 of 7 ==1023956== at 0x4849013: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==1023956== by 0x1122C1: gnu_cxx::new_allocator<Client>::allocate(unsigned long, void const) (new_allocator.h:127) ==1023956== by 0x111FFB: gnu_cxx::alloc_traits<std::allocator<Client>, Client>::allocate(std::allocator<Client>&, unsigned long) (alloc_traits.h:133) ==1023956== by 0x111B5B: std::_Vector_base<Client, std::allocator<Client> >::_M_allocate(unsigned long) (stl_vector.h:346) ==1023956== by 0x11147A: std::vector<Client, std::allocator<Client*> >::_M_realloc_insert(gnu_cxx::normal_iterator<Client*, std::vector<Client, std::allocator<Client> > >, Client const&) (vector.tcc:440) ==1023956== by 0x110F2D: std::vector<Client, std::allocator<Client> >::push_back(Client const&) (stl_vector.h:1198) ==1023956== by 0x1128D2: ServerManager::createClient(Client) (ServerManager.cpp:17) ==1023956== by 0x10C1D3: Server::newClientConnection() (Server.cpp:88) ==1023956== by 0x10C34B: Server::runServer() (Server.cpp:104) ==1023956== by 0x10C83D: Server::inicializeServer() (Server.cpp:164) ==1023956== by 0x10BAF0: main (main.cpp:29) ==1023956== ==1023956== 32 bytes in 1 blocks are still reachable in loss record 2 of 7 ==1023956== at 0x4849013: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==1023956== by 0x10D929: gnu_cxx::new_allocator::allocate(unsigned long, void const*) (new_allocator.h:127) ==1023956== by 0x10D74A: __gnu_cxx::alloc_traits<std::allocator, pollfd>::allocate(std::allocator&, unsigned long) (alloc_traits.h:133) ==1023956== by 0x10D53D: std::_Vector_base<pollfd, std::allocator >::_M_allocate(unsigned long) (stl_vector.h:346) ==1023956== by 0x10D008: std::vector<pollfd, std::allocator >::_M_realloc_insert(gnu_cxx::normal_iterator<pollfd*, std::vector<pollfd, std::allocator > >, pollfd const&) (vector.tcc:440) ==1023956== by 0x10CCF7: std::vector<pollfd, std::allocator >::push_back(pollfd const&) (stl_vector.h:1198) ==1023956== by 0x10C1A2: Server::newClientConnection() (Server.cpp:86) ==1023956== by 0x10C34B: Server::runServer() (Server.cpp:104) ==1023956== by 0x10C83D: Server::inicializeServer() (Server.cpp:164) ==1023956== by 0x10BAF0: main (main.cpp:29) ==1023956== ==1023956== 32 bytes in 1 blocks are still reachable in loss record 3 of 7 ==1023956== at 0x4849013: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==1023956== by 0x10FB19: gnu_cxx::new_allocator<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >::allocate(unsigned long, void const*) (new_allocator.h:127) ==1023956== by 0x10F749: gnu_cxx::alloc_traits<std::allocator<std::cxx11::basic_string<char, std::char_traits, std::allocator > >, std::cxx11::basic_string<char, std::char_traits, std::allocator > >::allocate(std::allocator<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >&, unsigned long) (alloc_traits.h:133) ==1023956== by 0x10F27F: std::_Vector_base<std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::cxx11::basic_string<char, std::char_traits, std::allocator > > >::_M_allocate(unsigned long) (stl_vector.h:346) ==1023956== by 0x10EFEA: std::vector<std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::cxx11::basic_string<char, std::char_traits, std::allocator > > >::_M_realloc_insert(gnu_cxx::normal_iterator<std::cxx11::basic_string<char, std::char_traits, std::allocator >*, std::vector<std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::cxx11::basic_string<char, std::char_traits, std::allocator > > > >, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&) (vector.tcc:440) ==1023956== by 0x10EA7B: std::vector<std::cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::cxx11::basic_string<char, std::char_traits, std::allocator > > >::push_back(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&) (stl_vector.h:1198) ==1023956== by 0x117694: splitNewLine(std::cxx11::basic_string<char, std::char_traits, std::allocator >) (ServerManager.cpp:530) ==1023956== by 0x11785D: ServerManager::handleIrcCmds(std::cxx11::basic_string<char, std::char_traits, std::allocator >, int, std::cxx11::basic_string<char, std::char_traits, std::allocator >) (ServerManager.cpp:542) ==1023956== by 0x10C433: Server::runServer() (Server.cpp:111) ==1023956== by 0x10C83D: Server::inicializeServer() (Server.cpp:164) ==1023956== by 0x10BAF0: main (main.cpp:29) ==1023956== ==1023956== 61 bytes in 1 blocks are still reachable in loss record 4 of 7 ==1023956== at 0x4849013: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==1023956== by 0x49BA0BD: std::__cxx11::basic_string<char, std::char_traits, std::allocator >::_M_mutate(unsigned long, unsigned long, char const*, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30) ==1023956== by 0x49BBB4F: std::cxx11::basic_string<char, std::char_traits, std::allocator >::_M_append(char const, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30) ==1023956== by 0x10E1DC: Client::saveBuffer(std::cxx11::basic_string<char, std::char_traits, std::allocator >) (Client.cpp:62) ==1023956== by 0x11781B: ServerManager::handleIrcCmds(std::cxx11::basic_string<char, std::char_traits, std::allocator >, int, std::__cxx11::basic_string<char, std::char_traits, std::allocator >) (ServerManager.cpp:540) ==1023956== by 0x10C433: Server::runServer() (Server.cpp:111) ==1023956== by 0x10C83D: Server::inicializeServer() (Server.cpp:164) ==1023956== by 0x10BAF0: main (main.cpp:29) ==1023956== ==1023956== 288 bytes in 2 blocks are still reachable in loss record 5 of 7 ==1023956== at 0x4849013: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==1023956== by 0x10C1AC: Server::newClientConnection() (Server.cpp:87) ==1023956== by 0x10C34B: Server::runServer() (Server.cpp:104) ==1023956== by 0x10C83D: Server::inicializeServer() (Server.cpp:164) ==1023956== by 0x10BAF0: main (main.cpp:29) ==1023956== ==1023956== 1,024 bytes in 1 blocks are still reachable in loss record 6 of 7 ==1023956== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==1023956== by 0x4B38BA3: _IO_file_doallocate (filedoalloc.c:101) ==1023956== by 0x4B47CDF: _IO_doallocbuf (genops.c:347) ==1023956== by 0x4B46F5F: _IO_file_overflow@@GLIBC_2.2.5 (fileops.c:744) ==1023956== by 0x4B456D4: _IO_new_file_xsputn (fileops.c:1243) ==1023956== by 0x4B456D4: _IO_file_xsputn@@GLIBC_2.2.5 (fileops.c:1196) ==1023956== by 0x4B39FD6: fwrite (iofwrite.c:39) ==1023956== by 0x49AAB64: std::basic_ostream<char, std::char_traits >& std::__ostream_insert<char, std::char_traits >(std::basic_ostream<char, std::char_traits >&, char const, long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30) ==1023956== by 0x49AAEBA: std::basic_ostream<char, std::char_traits >& std::operator<< <std::char_traits >(std::basic_ostream<char, std::char_traits >&, char const*) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30) ==1023956== by 0x10C80A: Server::inicializeServer() (Server.cpp:159) ==1023956== by 0x10BAF0: main (main.cpp:29) ==1023956== ==1023956== 72,704 bytes in 1 blocks are still reachable in loss record 7 of 7 ==1023956== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==1023956== by 0x4918939: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30) ==1023956== by 0x400647D: call_init.part.0 (dl-init.c:70) ==1023956== by 0x4006567: call_init (dl-init.c:33) ==1023956== by 0x4006567: _dl_init (dl-init.c:117) ==1023956== by 0x40202C9: ??? (in /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2) ==1023956== by 0x2: ??? ==1023956== by 0x1FFEFFFBC2: ??? ==1023956== by 0x1FFEFFFBCC: ??? ==1023956== by 0x1FFEFFFBD1: ??? ==1023956== ==1023956== LEAK SUMMARY: ==1023956== definitely lost: 0 bytes in 0 blocks ==1023956== indirectly lost: 0 bytes in 0 blocks ==1023956== possibly lost: 0 bytes in 0 blocks ==1023956== still reachable: 74,157 bytes in 8 blocks ==1023956== suppressed: 0 bytes in 0 blocks ==1023956== ==1023956== For lists of detected and suppressed errors, rerun with: -s ==1023956== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

paulasbia commented 3 months ago

CRTL+D is not working

  1. Start our server
  2. Start a nc user
  3. Digit PASS,' ', CTRL+D, 123
  4. Try setting a NICK