Bug Summary

File:home/maarten/src/libreoffice/core/starmath/source/smdetect.cxx
Warning:line 92, column 10
Potential leak of memory pointed to by 'aStorage.pObj'

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 smdetect.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/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/starmath/inc -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 -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/starmath/source/smdetect.cxx
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "smdetect.hxx"
21#include <cppuhelper/supportsservice.hxx>
22#include <com/sun/star/io/XInputStream.hpp>
23#include <com/sun/star/ucb/ContentCreationException.hpp>
24#include <com/sun/star/uno/XComponentContext.hpp>
25#include <sfx2/docfile.hxx>
26#include <unotools/mediadescriptor.hxx>
27#include <sal/log.hxx>
28#include <sot/storage.hxx>
29#include <tools/diagnose_ex.h>
30
31#include "eqnolefilehdr.hxx"
32
33using namespace ::com::sun::star;
34using namespace ::com::sun::star::uno;
35using namespace ::com::sun::star::io;
36using namespace ::com::sun::star::task;
37using namespace ::com::sun::star::beans;
38using namespace ::com::sun::star::lang;
39using utl::MediaDescriptor;
40
41SmFilterDetect::SmFilterDetect()
42{
43}
44
45SmFilterDetect::~SmFilterDetect()
46{
47}
48
49OUString SAL_CALL SmFilterDetect::detect( Sequence< PropertyValue >& lDescriptor )
50{
51 MediaDescriptor aMediaDesc( lDescriptor );
52 uno::Reference< io::XInputStream > xInStream ( aMediaDesc[MediaDescriptor::PROP_INPUTSTREAM()], uno::UNO_QUERY );
53 if ( !xInStream.is() )
1
Taking false branch
54 return OUString();
55
56 SfxMedium aMedium;
57 aMedium.UseInteractionHandler( false );
58 aMedium.setStreamToLoadFrom( xInStream, true );
59
60 SvStream *pInStrm = aMedium.GetInStream();
61 if ( !pInStrm || pInStrm->GetError() )
2
Assuming 'pInStrm' is non-null
3
Taking false branch
62 return OUString();
63
64 // Do not attempt to create an SotStorage on a
65 // 0-length stream as that would create the compound
66 // document header on the stream and effectively write to
67 // disk!
68 pInStrm->Seek( STREAM_SEEK_TO_BEGIN0L );
69 if ( pInStrm->remainingSize() == 0 )
4
Assuming the condition is false
5
Taking false branch
70 return OUString();
71
72 bool bStorageOk = false;
73 try
74 {
75 tools::SvRef<SotStorage> aStorage = new SotStorage( pInStrm, false );
6
Memory is allocated
76 bStorageOk = !aStorage->GetError();
77 if (bStorageOk
6.1
'bStorageOk' is false
)
7
Taking false branch
78 {
79 if ( aStorage->IsStream("Equation Native") )
80 {
81 sal_uInt8 nVersion;
82 if ( GetMathTypeVersion( aStorage.get(), nVersion ) && nVersion <=3 )
83 return "math_MathType_3x";
84 }
85 }
86 }
87 catch (const css::ucb::ContentCreationException &)
88 {
89 TOOLS_WARN_EXCEPTION("starmath", "SmFilterDetect::detect caught" )do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "starmath")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case
SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "SmFilterDetect::detect caught"
<< " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"starmath"), ("/home/maarten/src/libreoffice/core/starmath/source/smdetect.cxx"
":" "89" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "SmFilterDetect::detect caught" <<
" " << exceptionToString(tools_warn_exception)), 0); }
else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "SmFilterDetect::detect caught" << " " <<
exceptionToString(tools_warn_exception); ::sal::detail::log(
(::SAL_DETAIL_LOG_LEVEL_WARN), ("starmath"), ("/home/maarten/src/libreoffice/core/starmath/source/smdetect.cxx"
":" "89" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "SmFilterDetect::detect caught" << " " <<
exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("starmath"), ("/home/maarten/src/libreoffice/core/starmath/source/smdetect.cxx"
":" "89" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "SmFilterDetect::detect caught" <<
" " << exceptionToString(tools_warn_exception)), 0); }
else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "SmFilterDetect::detect caught" << " " <<
exceptionToString(tools_warn_exception); ::sal::detail::log(
(::SAL_DETAIL_LOG_LEVEL_WARN), ("starmath"), ("/home/maarten/src/libreoffice/core/starmath/source/smdetect.cxx"
":" "89" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
90 }
91
92 if (!bStorageOk)
8
Potential leak of memory pointed to by 'aStorage.pObj'
93 {
94 // 200 should be enough for the XML
95 // version, encoding and !DOCTYPE
96 // stuff I hope?
97 static const sal_uInt16 nBufferSize = 200;
98 char aBuffer[nBufferSize+1];
99 pInStrm->Seek( STREAM_SEEK_TO_BEGIN0L );
100 pInStrm->StartReadingUnicodeText( RTL_TEXTENCODING_DONTKNOW(((rtl_TextEncoding) 0)) ); // avoid BOM marker
101 auto nBytesRead = pInStrm->ReadBytes( aBuffer, nBufferSize );
102 if (nBytesRead >= 6)
103 {
104 aBuffer[nBytesRead] = 0;
105 bool bIsMathType = false;
106 if (0 == strncmp( "<?xml", aBuffer, 5))
107 bIsMathType = (strstr( aBuffer, "<math>" ) ||
108 strstr( aBuffer, "<math " ) ||
109 strstr( aBuffer, "<math:math " ));
110 else
111 // this is the old <math tag to MathML in the beginning of the XML file
112 bIsMathType = (0 == strncmp( "<math ", aBuffer, 6) ||
113 0 == strncmp( "<math> ", aBuffer, 7) ||
114 0 == strncmp( "<math:math> ", aBuffer, 12));
115
116 if ( bIsMathType )
117 return "math_MathML_XML_Math";
118 }
119 }
120
121 return OUString();
122}
123
124/* XServiceInfo */
125OUString SAL_CALL SmFilterDetect::getImplementationName()
126{
127 return "com.sun.star.comp.math.FormatDetector";
128}
129
130/* XServiceInfo */
131sal_Bool SAL_CALL SmFilterDetect::supportsService( const OUString& sServiceName )
132{
133 return cppu::supportsService(this, sServiceName);
134}
135
136/* XServiceInfo */
137Sequence< OUString > SAL_CALL SmFilterDetect::getSupportedServiceNames()
138{
139 return { "com.sun.star.frame.ExtendedTypeDetection" };
140}
141
142extern "C" SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) uno::XInterface*
143math_FormatDetector_get_implementation(uno::XComponentContext* /*pCtx*/,
144 uno::Sequence<uno::Any> const& /*rSeq*/)
145{
146 return cppu::acquire(new SmFilterDetect);
147}
148
149/* vim:set shiftwidth=4 softtabstop=4 expandtab: */