summaryrefslogtreecommitdiff
path: root/hwpfilter
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-07-03 09:10:17 +0200
committerStephan Bergmann <sbergman@redhat.com>2014-07-03 13:11:58 +0200
commit2617def8d1430e093f6a482a72727b2965a8a8a6 (patch)
treef05a609146b860990646647430814425254001b1 /hwpfilter
parent729d16f7f4eb0ce8d9898b46f6c4f16b01c797ea (diff)
Fix (harmless) stack-use-after-return
...as reported by -fsanitize=address CppunitTest_hwpfilter_test_hwpfilter, where stack-local HStream stream from HwpReader::filter is still referenced from HStreamIODev in HStreamIODev::close HStreamIODev::~HStreamIODev HWPFile::~HWPFile HwpReader::~HwpReader which is only harmless because HStream::closeInput is a nop. Change-Id: Idbc5539ab5f463ec6d5d72f428ce60327ebdb063
Diffstat (limited to 'hwpfilter')
-rw-r--r--hwpfilter/source/hiodev.cxx18
-rw-r--r--hwpfilter/source/hiodev.h5
-rw-r--r--hwpfilter/source/hwpfile.cxx4
-rw-r--r--hwpfilter/source/hwpfile.h4
-rw-r--r--hwpfilter/source/hwpreader.cxx7
5 files changed, 20 insertions, 18 deletions
diff --git a/hwpfilter/source/hiodev.cxx b/hwpfilter/source/hiodev.cxx
index d5f993d500c2..9e92219c62ff 100644
--- a/hwpfilter/source/hiodev.cxx
+++ b/hwpfilter/source/hiodev.cxx
@@ -107,7 +107,7 @@ int HIODev::read4b(void *ptr, int nmemb)
// hfileiodev class
-HStreamIODev::HStreamIODev(HStream & stream):_stream(stream)
+HStreamIODev::HStreamIODev(HStream * stream):_stream(stream)
{
init();
}
@@ -128,7 +128,7 @@ void HStreamIODev::init()
bool HStreamIODev::open()
{
- if (!(_stream.available()))
+ if (!(_stream->available()))
return false;
return true;
}
@@ -148,7 +148,7 @@ void HStreamIODev::close(void)
if (_gzfp)
gz_close(_gzfp); /* gz_close() calls stream_closeInput() */
else
- _stream.closeInput();
+ _stream->closeInput();
_gzfp = NULL;
}
@@ -164,7 +164,7 @@ bool HStreamIODev::setCompressed(bool flag)
{
compressed = flag;
if (flag == true)
- return 0 != (_gzfp = gz_open(_stream));
+ return 0 != (_gzfp = gz_open(*_stream));
else if (_gzfp)
{
gz_flush(_gzfp, Z_FINISH);
@@ -181,7 +181,7 @@ bool HStreamIODev::setCompressed(bool flag)
int HStreamIODev::read1b()
{
- int res = (compressed) ? GZREAD(rBuf, 1) : _stream.readBytes(rBuf, 1);
+ int res = (compressed) ? GZREAD(rBuf, 1) : _stream->readBytes(rBuf, 1);
if (res <= 0)
return -1;
@@ -192,7 +192,7 @@ int HStreamIODev::read1b()
int HStreamIODev::read2b()
{
- int res = (compressed) ? GZREAD(rBuf, 2) : _stream.readBytes(rBuf, 2);
+ int res = (compressed) ? GZREAD(rBuf, 2) : _stream->readBytes(rBuf, 2);
if (res <= 0)
return -1;
@@ -203,7 +203,7 @@ int HStreamIODev::read2b()
int HStreamIODev::read4b()
{
- int res = (compressed) ? GZREAD(rBuf, 4) : _stream.readBytes(rBuf, 4);
+ int res = (compressed) ? GZREAD(rBuf, 4) : _stream->readBytes(rBuf, 4);
if (res <= 0)
return -1;
@@ -216,7 +216,7 @@ int HStreamIODev::read4b()
int HStreamIODev::readBlock(void *ptr, int size)
{
int count =
- (compressed) ? GZREAD(ptr, size) : _stream.readBytes((byte *) ptr,
+ (compressed) ? GZREAD(ptr, size) : _stream->readBytes((byte *) ptr,
size);
@@ -242,7 +242,7 @@ int HStreamIODev::skipBlock(int size)
return size - remain;
}
}
- return _stream.skipBytes(size);
+ return _stream->skipBytes(size);
}
diff --git a/hwpfilter/source/hiodev.h b/hwpfilter/source/hiodev.h
index 40783f5f9cf3..a47de8f095bc 100644
--- a/hwpfilter/source/hiodev.h
+++ b/hwpfilter/source/hiodev.h
@@ -29,6 +29,7 @@
#include <stdio.h>
+#include <boost/scoped_ptr.hpp>
#include <sal/types.h>
#include "hwplib.h"
@@ -74,10 +75,10 @@ class HStreamIODev : public HIODev
{
private:
/* zlib으로 압축을 풀기 위한 자료 구조 */
+ boost::scoped_ptr<HStream> _stream;
gz_stream *_gzfp;
- HStream& _stream;
public:
- HStreamIODev(HStream& stream);
+ HStreamIODev(HStream* stream);
virtual ~HStreamIODev();
/**
* Check whether the stream is available
diff --git a/hwpfilter/source/hwpfile.cxx b/hwpfilter/source/hwpfile.cxx
index 5f5b8e3c3ebc..c4a0bfc63430 100644
--- a/hwpfilter/source/hwpfile.cxx
+++ b/hwpfilter/source/hwpfile.cxx
@@ -81,7 +81,7 @@ HWPFile::~HWPFile()
}
}
-int HWPFile::ReadHwpFile(HStream & stream)
+int HWPFile::ReadHwpFile(HStream * stream)
{
if (Open(stream) != HWP_NoError)
return State();
@@ -108,7 +108,7 @@ int detect_hwp_version(const char *str)
// HIODev wrapper
-int HWPFile::Open(HStream & stream)
+int HWPFile::Open(HStream * stream)
{
HStreamIODev *hstreamio = new HStreamIODev(stream);
diff --git a/hwpfilter/source/hwpfile.h b/hwpfilter/source/hwpfile.h
index f812f81c455f..82ba103a991e 100644
--- a/hwpfilter/source/hwpfile.h
+++ b/hwpfilter/source/hwpfile.h
@@ -110,7 +110,7 @@ class DLLEXPORT HWPFile
* @returns 0 if success, otherwise error code
* @see State()
*/
- int Open( HStream & );
+ int Open( HStream * );
/**
* Say current state
@@ -170,7 +170,7 @@ class DLLEXPORT HWPFile
/**
* Reads all information of hwp file from stream
*/
- int ReadHwpFile( HStream &);
+ int ReadHwpFile( HStream *);
/**
* Reads document information of hwp file from HIODev
*/
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index f140add0de1d..914f6b4e9392 100644
--- a/hwpfilter/source/hwpreader.cxx
+++ b/hwpfilter/source/hwpreader.cxx
@@ -25,6 +25,7 @@
#include <math.h>
#include <comphelper/newarray.hxx>
+#include <o3tl/heap_ptr.hxx>
#include "fontmap.hxx"
#include "formula.h"
@@ -130,7 +131,7 @@ sal_Bool HwpReader::filter(const Sequence< PropertyValue >& rDescriptor) throw(R
Reference< XInputStream > xInputStream(
aDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM()], UNO_QUERY_THROW);
- HStream stream;
+ o3tl::heap_ptr<HStream> stream(new HStream);
Sequence < sal_Int8 > aBuffer;
sal_Int32 nRead, nBlock = 32768, nTotal = 0;
while( true )
@@ -138,13 +139,13 @@ sal_Bool HwpReader::filter(const Sequence< PropertyValue >& rDescriptor) throw(R
nRead = xInputStream->readBytes(aBuffer, nBlock);
if( nRead == 0 )
break;
- stream.addData( (const byte *)aBuffer.getConstArray(), nRead );
+ stream->addData( (const byte *)aBuffer.getConstArray(), nRead );
nTotal += nRead;
}
if( nTotal == 0 ) return sal_False;
- if (hwpfile.ReadHwpFile(stream))
+ if (hwpfile.ReadHwpFile(stream.release()))
return sal_False;
if (m_rxDocumentHandler.is())