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/users.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/users.cpp') diff --git a/src/users.cpp b/src/users.cpp index f211f6b49..a4af8914b 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -633,7 +633,8 @@ void OperInfo::init() AllowedPrivs.insert(mypriv); } - for (unsigned char* c = (unsigned char*)tag->getString("usermodes").c_str(); *c; ++c) + std::string modes = tag->getString("usermodes"); + for (std::string::const_iterator c = modes.begin(); c != modes.end(); ++c) { if (*c == '*') { @@ -645,7 +646,8 @@ void OperInfo::init() } } - for (unsigned char* c = (unsigned char*)tag->getString("chanmodes").c_str(); *c; ++c) + modes = tag->getString("chanmodes"); + for (std::string::const_iterator c = modes.begin(); c != modes.end(); ++c) { if (*c == '*') { -- cgit v1.2.3