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; | 	m_HandledByDebugger = handled; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| posix_error::~posix_error() throw() | const char* posix_error::what() const noexcept | ||||||
| { | { | ||||||
| 	free(m_Message); | 	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"; | ||||||
|  | 			} | ||||||
| 
 | 
 | ||||||
| const char *posix_error::what() const throw() | 			const std::string* fname = boost::get_error_info<boost::errinfo_file_name>(*this); | ||||||
| { |  | ||||||
| 	if (!m_Message) { |  | ||||||
| 		std::ostringstream msgbuf; |  | ||||||
| 
 | 
 | ||||||
| 		const char * const *func = boost::get_error_info<boost::errinfo_api_function>(*this); | 			if (fname) { | ||||||
|  | 				m_Message += " for file '" + *fname + "'"; | ||||||
|  | 			} | ||||||
| 
 | 
 | ||||||
| 		if (func) | 			m_Message += " failed"; | ||||||
| 			msgbuf << "Function call '" << *func << "'"; |  | ||||||
| 		else |  | ||||||
| 			msgbuf << "Function call"; |  | ||||||
| 
 | 
 | ||||||
| 		const std::string *fname = boost::get_error_info<boost::errinfo_file_name>(*this); | 			const int* errnum = boost::get_error_info<boost::errinfo_errno>(*this); | ||||||
| 
 | 
 | ||||||
| 		if (fname) | 			if (errnum) { | ||||||
| 			msgbuf << " for file '" << *fname << "'"; | 				m_Message += " with error code " + std::to_string(*errnum) + ", '" + strerror(*errnum) + "'"; | ||||||
| 
 | 			} | ||||||
| 		msgbuf << " failed"; | 		} catch (const std::bad_alloc&) { | ||||||
| 
 | 			m_Message.Clear(); | ||||||
| 		const int *errnum = boost::get_error_info<boost::errinfo_errno>(*this); | 			return "Exception in 'posix_error::what()': bad_alloc"; | ||||||
| 
 | 		} catch (...) { | ||||||
| 		if (errnum) | 			m_Message.Clear(); | ||||||
| 			msgbuf << " with error code " << *errnum << ", '" << strerror(*errnum) << "'"; | 			return "Exception in 'posix_error::what()'"; | ||||||
| 
 | 		} | ||||||
| 		String str = msgbuf.str(); |  | ||||||
| 		m_Message = strdup(str.CStr()); |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return m_Message; | 	return m_Message.CStr(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ValidationError::ValidationError(const ConfigObject::Ptr& object, const std::vector<String>& attributePath, const String& message) | 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 { | class posix_error : virtual public std::exception, virtual public boost::exception { | ||||||
| public: | public: | ||||||
| 	~posix_error() throw() override; | 	const char* what() const noexcept final; | ||||||
| 
 |  | ||||||
| 	const char *what(void) const throw() final; |  | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
| 	mutable char *m_Message{nullptr}; | 	mutable String m_Message; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| #ifdef _WIN32 | #ifdef _WIN32 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user