From 83c7cc45daf6fb1f8c36f15297a4657e45a34e88 Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Sun, 23 Sep 2012 02:51:16 +0200 Subject: Fix undefined behavior caused by referencing the returned buffer by std::string::c_str() when the object is temporary Thanks to @ChrisTX for pointing this out Fixes #257 reported by @helloall --- src/modules/m_operlevels.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/modules/m_operlevels.cpp') diff --git a/src/modules/m_operlevels.cpp b/src/modules/m_operlevels.cpp index 7e28f6c21..4fc4c6aef 100644 --- a/src/modules/m_operlevels.cpp +++ b/src/modules/m_operlevels.cpp @@ -42,8 +42,11 @@ class ModuleOperLevels : public Module // oper killing an oper? if (IS_OPER(dest) && IS_OPER(source)) { - long dest_level = atol(dest->oper->getConfig("level").c_str()); - long source_level = atol(source->oper->getConfig("level").c_str()); + std::string level = dest->oper->getConfig("level"); + long dest_level = atol(level.c_str()); + level = source->oper->getConfig("level"); + long source_level = atol(level.c_str()); + if (dest_level > source_level) { if (IS_LOCAL(source)) ServerInstance->SNO->WriteGlobalSno('a', "Oper %s (level %ld) attempted to /kill a higher oper: %s (level %ld): Reason: %s",source->nick.c_str(),source_level,dest->nick.c_str(),dest_level,reason.c_str()); -- cgit v1.2.3