Commits

Adrian Buehlmann committed cba2f41

shellext: check return value of std::string::find_last_of

Not knowingly fixing a bug, but not checking it seems dangerous
to me.

substr is specified to throw a std C++ lib out_of_range exception, but we
haven't set up any catch handlers and we are not allowed to throw C++
exceptions across COM interface calls anyway.

Comments (0)

Files changed (2)

win32/shellext/Registry.cpp

 CRegStdBase::CRegStdBase (const tstring& key, bool force, HKEY base, REGSAM sam)
     : CRegBaseCommon<tstring> (key, force, base, sam)
 {
-	tstring::size_type pos = key.find_last_of(_T('\\'));
-    m_path = key.substr(0, pos);
-	m_key = key.substr(pos + 1);
+    tstring::size_type pos = key.find_last_of(_T('\\'));
+    if (pos != tstring::npos)
+    {
+        m_path = key.substr(0, pos);
+        m_key = key.substr(pos + 1);
+    }
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////////

win32/shellext/TortoiseUtils.cpp

     if (filename.empty())
         return filename;
     std::string::size_type pos = filename.find_last_of("\\");
+    if (pos == std::string::npos)
+        return "";
     std::string myfilename = filename.substr(0, pos);
     if (myfilename.size() > 0 && myfilename[myfilename.size()-1] == ':')
         myfilename.push_back('\\');
     if (filename.empty())
         return filename;
     std::string::size_type pos = filename.find_last_of("\\");
+    if (pos == std::string::npos)
+        return filename;
     return filename.substr(pos+1);
 }