mirror of
				https://github.com/Icinga/icinga2.git
				synced 2025-10-28 09:44:05 +01:00 
			
		
		
		
	Fix double-free error in posix_error::what()
This commit is contained in:
		
							parent
							
								
									2063d2bdbc
								
							
						
					
					
						commit
						db4e984989
					
				| @ -335,40 +335,40 @@ void ScriptError::SetHandledByDebugger(bool handled) | ||||
| 	m_HandledByDebugger = handled; | ||||
| } | ||||
| 
 | ||||
| posix_error::~posix_error() throw() | ||||
| const char* posix_error::what() const noexcept | ||||
| { | ||||
| 	free(m_Message); | ||||
| } | ||||
| 
 | ||||
| const char *posix_error::what() const throw() | ||||
| { | ||||
| 	if (!m_Message) { | ||||
| 		std::ostringstream msgbuf; | ||||
| 
 | ||||
| 		const char * const *func = boost::get_error_info<boost::errinfo_api_function>(*this); | ||||
| 
 | ||||
| 		if (func) | ||||
| 			msgbuf << "Function call '" << *func << "'"; | ||||
| 		else | ||||
| 			msgbuf << "Function call"; | ||||
| 
 | ||||
| 		const std::string *fname = boost::get_error_info<boost::errinfo_file_name>(*this); | ||||
| 
 | ||||
| 		if (fname) | ||||
| 			msgbuf << " for file '" << *fname << "'"; | ||||
| 
 | ||||
| 		msgbuf << " failed"; | ||||
| 
 | ||||
| 		const int *errnum = boost::get_error_info<boost::errinfo_errno>(*this); | ||||
| 
 | ||||
| 		if (errnum) | ||||
| 			msgbuf << " with error code " << *errnum << ", '" << strerror(*errnum) << "'"; | ||||
| 
 | ||||
| 		String str = msgbuf.str(); | ||||
| 		m_Message = strdup(str.CStr()); | ||||
| 	if (m_Message.IsEmpty()) { | ||||
| 		try { | ||||
| 			const char* const* func = boost::get_error_info<boost::errinfo_api_function>(*this); | ||||
| 			if (func) { | ||||
| 				m_Message += "Function call '" + std::string(*func) + "'"; | ||||
| 			} else { | ||||
| 				m_Message += "Function call"; | ||||
| 			} | ||||
| 
 | ||||
| 	return m_Message; | ||||
| 			const std::string* fname = boost::get_error_info<boost::errinfo_file_name>(*this); | ||||
| 
 | ||||
| 			if (fname) { | ||||
| 				m_Message += " for file '" + *fname + "'"; | ||||
| 			} | ||||
| 
 | ||||
| 			m_Message += " failed"; | ||||
| 
 | ||||
| 			const int* errnum = boost::get_error_info<boost::errinfo_errno>(*this); | ||||
| 
 | ||||
| 			if (errnum) { | ||||
| 				m_Message += " with error code " + std::to_string(*errnum) + ", '" + strerror(*errnum) + "'"; | ||||
| 			} | ||||
| 		} catch (const std::bad_alloc&) { | ||||
| 			m_Message.Clear(); | ||||
| 			return "Exception in 'posix_error::what()': bad_alloc"; | ||||
| 		} catch (...) { | ||||
| 			m_Message.Clear(); | ||||
| 			return "Exception in 'posix_error::what()'"; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return m_Message.CStr(); | ||||
| } | ||||
| 
 | ||||
| ValidationError::ValidationError(const ConfigObject::Ptr& object, const std::vector<String>& attributePath, const String& message) | ||||
|  | ||||
| @ -118,12 +118,10 @@ String DiagnosticInformation(const boost::exception_ptr& eptr, bool verbose = tr | ||||
| 
 | ||||
| class posix_error : virtual public std::exception, virtual public boost::exception { | ||||
| public: | ||||
| 	~posix_error() throw() override; | ||||
| 
 | ||||
| 	const char *what(void) const throw() final; | ||||
| 	const char* what() const noexcept final; | ||||
| 
 | ||||
| private: | ||||
| 	mutable char *m_Message{nullptr}; | ||||
| 	mutable String m_Message; | ||||
| }; | ||||
| 
 | ||||
| #ifdef _WIN32 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user