[project @ 2005-03-01 03:18:40 by unknown_lamer]
authorunknown_lamer <unknown>
Tue, 1 Mar 2005 03:18:40 +0000 (03:18 +0000)
committerunknown_lamer <unknown>
Tue, 1 Mar 2005 03:18:40 +0000 (03:18 +0000)
Fixed a potential segfault in the Parser

2005-02-28  Clinton Ebadi  <clinton@unknownlamer.org>

* source/Parser.C (parseLine): use map<>::find and an iterator to
find the IRC command instead of map<>::operator[] to avoid a
potential segfault

* source/Bot.C (waitForInput): Removed commented out code

ChangeLog
source/Bot.C
source/Parser.C

index 18e5b53..471a4ae 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2005-02-28  Clinton Ebadi  <clinton@unknownlamer.org>
 
+       * source/Parser.C (parseLine): use map<>::find and an iterator to
+       find the IRC command instead of map<>::operator[] to avoid a
+       potential segfault
+
+       * source/Bot.C (waitForInput): Removed commented out code
+
        * source/Socket.C (readLine): return String (buf.c_str ()) instead
        of String (buf) so that only the buffer up to the first null is returned
        (readLine): Added a comment explaining the usage of buf
index e799f0f..cfcd972 100644 (file)
@@ -354,24 +354,6 @@ Bot::waitForInput()
       if (serverConnection->handleInput())
         nextServer();
 
-//     std::list<DCCConnection *>::iterator it = dccConnections.begin();
-//     std::list<DCCConnection *>::iterator it2;
-
-//     while (it != dccConnections.end()) {
-//       it2 = it;
-//       ++it;
-// #ifdef _HPUX_SOURCE
-//       if (rd & (*it2)->getFileDescriptor()) {
-// #else
-//      if (FD_ISSET((*it2)->getFileDescriptor(), &rd)) {
-// #endif
-//         if ((*it2)->handleInput()) {
-//           delete *it2;
-//           dccConnections.erase(it2);
-//         }
-//       }
-//     }
-//     }
     dccConnections->checkInput (rd);
   }
 
@@ -419,18 +401,6 @@ Bot::waitForInput()
          serverConnection->queue->sendJoin((*it).first, (*it).second->key);
   }
 
-//   std::list<DCCConnection *>::iterator it2;
-
-//   for (std::list<DCCConnection *>::iterator it = dccConnections.begin();
-//        it != dccConnections.end(); ) {
-//     it2 = it;
-//     ++it;
-//     if ((*it2)->autoRemove && currentTime >= (std::time_t)((*it2)->lastSpoken + Bot::DCC_DELAY)) {
-//       delete *it2;
-//       dccConnections.erase(it2);
-//     }
-//   }
-
   if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken + Bot::PING_TIME) && !sentPing) {
     serverConnection->queue->sendPing("Testing connection");
     sentPing = true;
index 33b0809..75768e0 100644 (file)
@@ -92,8 +92,18 @@ Parser::parseLine (ServerConnection * cnx, String line)
   String command = st.next_token ();
   String rest = st.rest ();
 
-  if (fptr temp_func = functions[command])
-    temp_func (cnx, from, rest);
+  // We must use map<>::find or else a new entry will be created in
+  // the map which will cause another lookup of the same invalid
+  // command to segfault the bot
+  std::map<std::string, fptr, std::less<std::string> >::const_iterator cit 
+    = functions.find (command);
+
+  if (cit != functions.end ())
+    {
+      fptr temp_func = cit->second;
+      temp_func (cnx, from, rest);
+    }
+
   delete from;
 }