Bug Summary

File:home/maarten/src/libreoffice/core/lotuswordpro/source/filter/bencont.cxx
Warning:line 225, column 16
Potential leak of memory pointed to by 'pPropertyName'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name bencont.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /home/maarten/src/libreoffice/core/lotuswordpro/inc -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/lotuswordpro/source/filter/bencont.cxx
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
6 *
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
9 *
10 * Sun Microsystems Inc., October, 2000
11 *
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 *
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 *
31 *
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
38 *
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
45 *
46 * The Initial Developer of the Original Code is: IBM Corporation
47 *
48 * Copyright: 2008 by IBM Corporation
49 *
50 * All Rights Reserved.
51 *
52 * Contributor(s): _______________________________________
53 *
54 *
55 ************************************************************************/
56#include "first.hxx"
57#include "tocread.hxx"
58#include <stdio.h>
59#include <algorithm>
60#include <osl/diagnose.h>
61
62namespace OpenStormBento
63{
64
65// String definitions
66const char gsBenMagicBytes[] = BEN_MAGIC_BYTES"\xA4""CM""\xA5""Hdr""\xD7";
67
68/**
69* New bento container from file stream
70* @param pointer to length of bento file
71* @param pointer to pointer of Bento Container object
72* @return error code
73*/
74sal_uLong BenOpenContainer(LwpSvStream * pStream, std::unique_ptr<LtcBenContainer>* ppContainer)
75{
76 *ppContainer = nullptr;
77
78 if (nullptr == pStream)
79 {
80 return BenErr_ContainerWithNoObjects;
81 }
82
83 std::unique_ptr<LtcBenContainer> pContainer(new LtcBenContainer(pStream));
84 if (pContainer->Open() != BenErr_OK) // delete two inputs
85 {
86 return BenErr_InvalidTOC;
87 }
88
89 *ppContainer = std::move(pContainer);
90 return BenErr_OK;
91}
92
93LtcBenContainer::~LtcBenContainer()
94{
95}
96
97BenError
98LtcBenContainer::Open() // delete two inputs
99{
100 BenError Err;
101 CBenTOCReader TOCReader(this);
102 if ((Err = TOCReader.ReadLabelAndTOC()) != BenErr_OK)
103 {
104 return Err;
105 }
106 return BenErr_OK;
107}
108
109void
110LtcBenContainer::RegisterPropertyName(const char * sPropertyName,
111 CBenPropertyName ** ppPropertyName)
112{
113 CUtListElmt * pPrevNamedObjectListElmt;
114 CBenNamedObject * pNamedObject = FindNamedObject(&cNamedObjects,
115 sPropertyName, &pPrevNamedObjectListElmt);
116
117 if (pNamedObject != nullptr)
6
Assuming the condition is false
7
Taking false branch
118 {
119 if (! pNamedObject->IsPropertyName())
120 return;
121 else *ppPropertyName = static_cast<CBenPropertyName *>(pNamedObject);
122 }
123 else
124 {
125 CUtListElmt * pPrevObject;
126 if (FindID(&cObjects, cNextAvailObjectID, &pPrevObject) != nullptr)
8
Assuming the condition is false
9
Taking false branch
127 return;
128
129 *ppPropertyName = new CBenPropertyName(this, cNextAvailObjectID,
10
Memory is allocated
130 pPrevObject, sPropertyName, pPrevNamedObjectListElmt);
131 ++cNextAvailObjectID;
132 }
133}
134
135CBenObject *
136LtcBenContainer::GetNextObject(CBenObject const * pCurrObject)
137{
138 return static_cast<CBenObject *>(cObjects.GetNextOrNULL(pCurrObject));
139}
140
141CBenObject *
142LtcBenContainer::FindNextObjectWithProperty(CBenObject * pCurrObject,
143 BenObjectID PropertyID)
144{
145 while ((pCurrObject = GetNextObject(pCurrObject)) != nullptr)
146 if (pCurrObject->UseProperty(PropertyID) != nullptr)
147 return pCurrObject;
148
149 return nullptr;
150}
151
152/**
153* Construction
154* @param Bento file stream pointer
155* @return
156*/
157LtcBenContainer::LtcBenContainer(LwpSvStream * pStream)
158 : cNextAvailObjectID(0)
159{
160 cpStream = pStream;
161 pStream->Seek(STREAM_SEEK_TO_END((sal_uInt64) 0xFFFFFFFFFFFFFFFFul));
162 m_ulLength = pStream->Tell();
163 pStream->Seek(STREAM_SEEK_TO_BEGIN0L);
164}
165
166/**
167* Read buffer for bento file with specified buffer
168* @param buffer pointer
169* @param buffer size
170* @param number of bytes read
171*/
172void LtcBenContainer::Read(void * pBuffer, size_t MaxSize,
173 size_t* pAmtRead)
174{
175 *pAmtRead = cpStream->Read(pBuffer, MaxSize);
176}
177/**
178* Read buffer from bento file with specified size
179* @param buffer pointer
180* @param number of bytes to be read
181* @return BenError
182*/
183BenError LtcBenContainer::ReadKnownSize(void * pBuffer, size_t Amt)
184{
185 size_t ulLength = cpStream->Read(pBuffer, Amt);
186 if (ulLength == Amt)
187 {
188 return BenErr_OK;
189 }
190 return BenErr_ReadPastEndOfContainer;
191}
192/**
193* Seek to position from the beginning of the bento file
194* @param position in container file from beginning
195*/
196void LtcBenContainer::SeekToPosition(BenContainerPos Pos)
197{
198 cpStream->Seek(Pos);
199}
200/**
201* Seek to position compare to end of bento file
202* @param position in container file from end
203*/
204void LtcBenContainer::SeekFromEnd(long Offset)
205{
206 cpStream->Seek(STREAM_SEEK_TO_END((sal_uInt64) 0xFFFFFFFFFFFFFFFFul));
207 cpStream->SeekRel(Offset);
208}
209/**
210* Find the next value stream with property name
211* @param string of property name
212* @return next value stream pointer with the property names
213*/
214LtcUtBenValueStream * LtcBenContainer::FindNextValueStreamWithPropertyName(const char * sPropertyName)
215{
216 CBenPropertyName * pPropertyName(nullptr);
217 RegisterPropertyName(sPropertyName, &pPropertyName); // Get property name object
5
Calling 'LtcBenContainer::RegisterPropertyName'
11
Returned allocated memory via 2nd parameter
218
219 if (nullptr == pPropertyName)
12
Taking false branch
220 return nullptr; // Property not exist
221
222 // Get current object
223 CBenObject * pObj =FindNextObjectWithProperty(nullptr, pPropertyName->GetID()); // Get next object with same property name
224 if (nullptr == pObj)
13
Assuming the condition is true
14
Taking true branch
225 return nullptr;
15
Potential leak of memory pointed to by 'pPropertyName'
226
227 CBenValue * pValue;
228 LtcUtBenValueStream * pValueStream;
229
230 pValue = pObj->UseValue(pPropertyName->GetID());
231
232 pValueStream = new LtcUtBenValueStream(pValue);
233
234 return pValueStream;
235}
236
237/**
238* Find the unique value stream with property name
239* @param string of property name
240* @return the only value stream pointer with the property names
241*/
242LtcUtBenValueStream * LtcBenContainer::FindValueStreamWithPropertyName(const char * sPropertyName)
243{
244 return FindNextValueStreamWithPropertyName(sPropertyName);
4
Calling 'LtcBenContainer::FindNextValueStreamWithPropertyName'
245}
246
247namespace
248{
249 void readDataInBlocks(SvStream& rSt, sal_uInt64 nDLen, std::vector<sal_uInt8>& rData)
250 {
251 //read data in blocks as its more likely large values are simply broken
252 //and we'll run out of data before we need to realloc
253 for (sal_uInt64 i = 0; i < nDLen; i+= SAL_MAX_UINT16((sal_uInt16) 0xFFFF))
254 {
255 size_t nOldSize = rData.size();
256 size_t nBlock = std::min<size_t>(SAL_MAX_UINT16((sal_uInt16) 0xFFFF), nDLen - nOldSize);
257 rData.resize(nOldSize + nBlock);
258 size_t nReadBlock = rSt.ReadBytes(rData.data() + nOldSize, nBlock);
259 if (nBlock != nReadBlock)
260 {
261 rData.resize(nOldSize + nReadBlock);
262 break;
263 }
264 }
265 }
266}
267
268/**
269* Find hazily according to object ID
270* @param pObjectname - format as "GrXX,XXXXXXXX" wherein XX is high part of object ID, and XXXXXXXX is low part
271*/
272std::vector<sal_uInt8> LtcBenContainer::GetGraphicData(const char *pObjectName)
273{
274 std::vector<sal_uInt8> aData;
275 if (!pObjectName)
1
Assuming 'pObjectName' is non-null
2
Taking false branch
276 {
277 return aData;
278 }
279 // construct the string of property name
280 char sSName[64]="";
281 char sDName[64]="";
282
283 sprintf(sSName, "%s-S", pObjectName);
284 sprintf(sDName, "%s-D", pObjectName);
285
286 /* traverse the found properties and construct the stream vectors */
287 // get S&D's stream and merge them together
288 std::unique_ptr<SvStream> xS(FindValueStreamWithPropertyName(sSName));
3
Calling 'LtcBenContainer::FindValueStreamWithPropertyName'
289 std::unique_ptr<SvStream> xD(FindValueStreamWithPropertyName(sDName));
290
291 sal_uInt64 nDLen = 0;
292 if (xD)
293 {
294 nDLen = xD->TellEnd();
295 }
296 sal_uInt64 nSLen = 0;
297 if (xS)
298 {
299 nSLen = xS->TellEnd();
300 }
301
302 sal_uInt64 nLen = nDLen + nSLen;
303 OSL_ENSURE(nLen > 0, "expected a non-0 length")do { if (true && (!(nLen > 0))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/lotuswordpro/source/filter/bencont.cxx"
":" "303" ": "), "%s", "expected a non-0 length"); } } while
(false)
;
304 // the 'D' stream is NULL or it has invalid length
305 if (nLen <= 0)
306 {
307 return aData;
308 }
309
310 if (xD)
311 {
312 readDataInBlocks(*xD, nDLen, aData);
313 xD.reset();
314 }
315 if (xS)
316 {
317 readDataInBlocks(*xS, nSLen, aData);
318 xS.reset();
319 }
320
321 return aData;
322}
323
324sal_uLong LtcBenContainer::remainingSize() const
325{
326 return m_ulLength - cpStream->Tell();
327}
328
329}// end namespace OpenStormBento
330
331/* vim:set shiftwidth=4 softtabstop=4 expandtab: */