[[project @ 2005-03-01 03:18:40 by unknown_lamer] unknown_lamer**20050301031840 Fixed a potential segfault in the Parser 2005-02-28 Clinton Ebadi * 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 ] { hunk ./ChangeLog 2 + + * 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 hunk ./source/Bot.C 357 -// std::list::iterator it = dccConnections.begin(); -// std::list::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); -// } -// } -// } -// } hunk ./source/Bot.C 404 -// std::list::iterator it2; - -// for (std::list::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); -// } -// } - hunk ./source/Parser.C 95 - 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 >::const_iterator cit + = functions.find (command); + + if (cit != functions.end ()) + { + fptr temp_func = cit->second; + temp_func (cnx, from, rest); + } + }