mirror of
https://git.freebsd.org/ports.git
synced 2025-05-03 12:06:39 -04:00
While here, backport critical security and compatibility fixes from upstream PR: 246106 Security: CVE-2018-20540
55 lines
1.6 KiB
Text
55 lines
1.6 KiB
Text
From 09d45518776489508f34098f1c159f58b856f459 Mon Sep 17 00:00:00 2001
|
|
From: Mateusz Loskot <mateusz@loskot.net>
|
|
Date: Sun, 20 Jan 2019 02:28:29 +0100
|
|
Subject: [PATCH] Ensure stream is deallocated in case of exception (#162)
|
|
|
|
Fixes #158
|
|
---
|
|
include/liblas/liblas.hpp | 32 ++++++++++++++++++++++++--------
|
|
1 file changed, 24 insertions(+), 8 deletions(-)
|
|
|
|
diff --git include/liblas/liblas.hpp include/liblas/liblas.hpp
|
|
index f5ad44e1..325de3ff 100644
|
|
--- include/liblas/liblas.hpp
|
|
+++ include/liblas/liblas.hpp
|
|
@@ -119,16 +119,32 @@ inline std::istream* Open(std::string const& filename, std::ios::openmode mode)
|
|
{
|
|
#ifdef USE_BOOST_IO
|
|
namespace io = boost::iostreams;
|
|
- io::stream<io::file_source>* ifs = new io::stream<io::file_source>();
|
|
- ifs->open(filename.c_str(), mode);
|
|
- if (ifs->is_open() == false) return NULL;
|
|
- return ifs;
|
|
+ io::stream<io::file_source>* ifs = NULL;
|
|
+ try
|
|
+ {
|
|
+ ifs = new io::stream<io::file_source>();
|
|
+ ifs->open(filename.c_str(), mode);
|
|
+ if (ifs->is_open() == false) return NULL;
|
|
+ return ifs;
|
|
+ }
|
|
+ catch (...)
|
|
+ {
|
|
+ delete ifs;
|
|
+ }
|
|
#else
|
|
- std::ifstream* ifs = new std::ifstream();
|
|
- ifs->open(filename.c_str(), mode);
|
|
- if (ifs->is_open() == false) return NULL;
|
|
- return ifs;
|
|
+ std::ifstream* ifs = NULL;
|
|
+ try
|
|
+ {
|
|
+ ifs = new std::ifstream();
|
|
+ ifs->open(filename.c_str(), mode);
|
|
+ if (ifs->is_open() == false) return NULL;
|
|
+ }
|
|
+ catch (...)
|
|
+ {
|
|
+ delete ifs;
|
|
+ }
|
|
#endif
|
|
+ return NULL;
|
|
}
|
|
|
|
/// Create file and open to write in binary mode.
|