Bug Summary

File:cppuhelper/source/exc_thrower.cxx
Location:line 111, column 13
Description:Access to field 'eTypeClass' results in a dereference of a null pointer (loaded from variable 'pTD')

Annotated Source Code

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 *
8 * OpenOffice.org - a multi-platform office productivity suite
9 *
10 * This file is part of OpenOffice.org.
11 *
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
15 *
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
21 *
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
26 *
27 ************************************************************************/
28
29
30#include "rtl/instance.hxx"
31#include "osl/diagnose.h"
32#include "osl/doublecheckedlocking.h"
33#include "osl/mutex.hxx"
34#include "uno/dispatcher.hxx"
35#include "uno/mapping.hxx"
36#include "cppuhelper/detail/XExceptionThrower.hpp"
37#include "com/sun/star/uno/RuntimeException.hpp"
38
39#include "cppuhelper/exc_hlp.hxx"
40
41#define OUSTR(x)::rtl::OUString( (&(x)[0]), ((sal_Int32)((sizeof (x) / sizeof
((x)[0]))-1)), (((rtl_TextEncoding) 11)) )
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x)(&(x)[0]), ((sal_Int32)((sizeof (x) / sizeof ((x)[0]))-1)
), (((rtl_TextEncoding) 11))
)
42
43
44using namespace ::rtl;
45using namespace ::osl;
46using namespace ::cppu;
47using namespace ::com::sun::star;
48using namespace ::com::sun::star::uno;
49
50namespace
51{
52
53using cppuhelper::detail::XExceptionThrower;
54
55//==============================================================================
56struct ExceptionThrower : public uno_Interface, XExceptionThrower
57{
58 inline ExceptionThrower();
59
60 virtual ~ExceptionThrower() {}
61
62 static inline Type const & getCppuType()
63 {
64 return ::getCppuType(
65 reinterpret_cast< Reference< XExceptionThrower > const * >(0) );
66 }
67
68 // XInterface
69 virtual Any SAL_CALL queryInterface( Type const & type )
70 throw (RuntimeException);
71 virtual void SAL_CALL acquire() throw ();
72 virtual void SAL_CALL release() throw ();
73
74 // XExceptionThrower
75 virtual void SAL_CALL throwException( Any const & exc ) throw (Exception);
76 virtual void SAL_CALL rethrowException() throw (Exception);
77};
78
79extern "C"
80{
81
82//------------------------------------------------------------------------------
83static void SAL_CALL ExceptionThrower_acquire_release_nop(
84 SAL_UNUSED_PARAMETER__attribute__ ((unused)) uno_Interface * )
85{}
86
87//------------------------------------------------------------------------------
88static void SAL_CALL ExceptionThrower_dispatch(
89 uno_Interface * pUnoI, typelib_TypeDescription const * pMemberType,
90 void * pReturn, void * pArgs [], uno_Any ** ppException )
91{
92 OSL_ASSERT( pMemberType->eTypeClass == typelib_TypeClass_INTERFACE_METHOD )do { if (true && (!(pMemberType->eTypeClass == typelib_TypeClass_INTERFACE_METHOD
))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppuhelper/source/exc_thrower.cxx"
":" "92" ": "), "OSL_ASSERT: %s", "pMemberType->eTypeClass == typelib_TypeClass_INTERFACE_METHOD"
); } } while (false)
;
93
94 switch (reinterpret_cast< typelib_InterfaceMemberTypeDescription * >(
1
Control jumps to 'case 0:' at line 98
95 const_cast< typelib_TypeDescription * >( pMemberType ) )->
96 nPosition)
97 {
98 case 0: // queryInterace()
99 {
100 Type const & rType_demanded =
101 *reinterpret_cast< Type const * >( pArgs[ 0 ] );
102 if (rType_demanded.equals(
103 ::getCppuType( reinterpret_cast<
104 Reference< XInterface > const * >(0) ) ) ||
105 rType_demanded.equals( ExceptionThrower::getCppuType() ))
106 {
107 typelib_TypeDescription * pTD = 0;
108 TYPELIB_DANGER_GET( &pTD, rType_demanded.getTypeLibType() ){ typelib_TypeDescriptionReference * pMacroTypeRef = (rType_demanded
.getTypeLibType()); typelib_TypeDescription ** ppMacroTypeDescr
= (&pTD); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr
, pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef
->pType->pWeakRef) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release
( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef
->pType; } }
;
109 uno_any_construct(
110 reinterpret_cast< uno_Any * >( pReturn ), &pUnoI, pTD, 0 );
111 TYPELIB_DANGER_RELEASE( pTD ){ if ((((pTD)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| ((pTD)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) typelib_typedescription_release( pTD ); }
;
2
Within the expansion of the macro 'TYPELIB_DANGER_RELEASE':
a
Access to field 'eTypeClass' results in a dereference of a null pointer (loaded from variable 'pTD')
112 }
113 else
114 {
115 uno_any_construct(
116 reinterpret_cast< uno_Any * >( pReturn ), 0, 0, 0 );
117 }
118 *ppException = 0;
119 break;
120 }
121 case 1: // acquire()
122 case 2: // release()
123 *ppException = 0;
124 break;
125 case 3: // throwException()
126 {
127 uno_Any * pAny = reinterpret_cast< uno_Any * >( pArgs[ 0 ] );
128 OSL_ASSERT( pAny->pType->eTypeClass == typelib_TypeClass_EXCEPTION )do { if (true && (!(pAny->pType->eTypeClass == typelib_TypeClass_EXCEPTION
))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/usr/local/src/libreoffice/cppuhelper/source/exc_thrower.cxx"
":" "128" ": "), "OSL_ASSERT: %s", "pAny->pType->eTypeClass == typelib_TypeClass_EXCEPTION"
); } } while (false)
;
129 uno_type_any_construct( *ppException, pAny->pData, pAny->pType, 0 );
130 break;
131 }
132 default:
133 {
134 OSL_ASSERT( 0 )do { if (true && (!(0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/usr/local/src/libreoffice/cppuhelper/source/exc_thrower.cxx"
":" "134" ": "), "OSL_ASSERT: %s", "0"); } } while (false)
;
135 RuntimeException exc(
136 OUSTR("not implemented!")::rtl::OUString( (&("not implemented!")[0]), ((sal_Int32)
((sizeof ("not implemented!") / sizeof (("not implemented!")[
0]))-1)), (((rtl_TextEncoding) 11)) )
, Reference< XInterface >() );
137 uno_type_any_construct(
138 *ppException, &exc, ::getCppuType( &exc ).getTypeLibType(), 0 );
139 break;
140 }
141 }
142}
143
144} // extern "C"
145
146//______________________________________________________________________________
147Any ExceptionThrower::queryInterface( Type const & type )
148 throw (RuntimeException)
149{
150 if (type.equals( ::getCppuType( reinterpret_cast<
151 Reference< XInterface > const * >(0) ) ) ||
152 type.equals( ExceptionThrower::getCppuType() ))
153 {
154 XExceptionThrower * that = static_cast< XExceptionThrower * >( this );
155 return Any( &that, type );
156 }
157 return Any();
158}
159
160//______________________________________________________________________________
161void ExceptionThrower::acquire() throw ()
162{
163}
164//______________________________________________________________________________
165void ExceptionThrower::release() throw ()
166{
167}
168
169//______________________________________________________________________________
170void ExceptionThrower::throwException( Any const & exc ) throw (Exception)
171{
172 OSL_FAIL( "unexpected!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppuhelper/source/exc_thrower.cxx"
":" "172" ": "), "%s", "unexpected!"); } } while (false)
;
173 throwException( exc );
174}
175
176//______________________________________________________________________________
177void ExceptionThrower::rethrowException() throw (Exception)
178{
179 throw;
180}
181
182//______________________________________________________________________________
183inline ExceptionThrower::ExceptionThrower()
184{
185 uno_Interface::acquire = ExceptionThrower_acquire_release_nop;
186 uno_Interface::release = ExceptionThrower_acquire_release_nop;
187 uno_Interface::pDispatcher = ExceptionThrower_dispatch;
188}
189
190class theExceptionThrower : public rtl::Static<ExceptionThrower, theExceptionThrower> {};
191
192} // anonymous namespace
193
194
195namespace cppu
196{
197
198//==============================================================================
199void SAL_CALL throwException( Any const & exc ) SAL_THROW( (Exception) )
200{
201 if (exc.getValueTypeClass() != TypeClass_EXCEPTION)
202 {
203 throw RuntimeException(
204 OUSTR("no UNO exception given "::rtl::OUString( (&("no UNO exception given " "(must be derived from com::sun::star::uno::Exception)!"
)[0]), ((sal_Int32)((sizeof ("no UNO exception given " "(must be derived from com::sun::star::uno::Exception)!"
) / sizeof (("no UNO exception given " "(must be derived from com::sun::star::uno::Exception)!"
)[0]))-1)), (((rtl_TextEncoding) 11)) )
205 "(must be derived from com::sun::star::uno::Exception)!")::rtl::OUString( (&("no UNO exception given " "(must be derived from com::sun::star::uno::Exception)!"
)[0]), ((sal_Int32)((sizeof ("no UNO exception given " "(must be derived from com::sun::star::uno::Exception)!"
) / sizeof (("no UNO exception given " "(must be derived from com::sun::star::uno::Exception)!"
)[0]))-1)), (((rtl_TextEncoding) 11)) )
,
206 Reference< XInterface >() );
207 }
208
209 Mapping uno2cpp(Environment(OUSTR(UNO_LB_UNO)::rtl::OUString( (&("uno")[0]), ((sal_Int32)((sizeof ("uno"
) / sizeof (("uno")[0]))-1)), (((rtl_TextEncoding) 11)) )
), Environment::getCurrent());
210 if (! uno2cpp.is())
211 {
212 throw RuntimeException(
213 OUSTR("cannot get binary UNO to C++ mapping!")::rtl::OUString( (&("cannot get binary UNO to C++ mapping!"
)[0]), ((sal_Int32)((sizeof ("cannot get binary UNO to C++ mapping!"
) / sizeof (("cannot get binary UNO to C++ mapping!")[0]))-1)
), (((rtl_TextEncoding) 11)) )
,
214 Reference< XInterface >() );
215 }
216
217 Reference< XExceptionThrower > xThrower;
218 uno2cpp.mapInterface(
219 reinterpret_cast< void ** >( &xThrower ),
220 static_cast< uno_Interface * >( &theExceptionThrower::get() ),
221 ExceptionThrower::getCppuType() );
222 OSL_ASSERT( xThrower.is() )do { if (true && (!(xThrower.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppuhelper/source/exc_thrower.cxx"
":" "222" ": "), "OSL_ASSERT: %s", "xThrower.is()"); } } while
(false)
;
223 xThrower->throwException( exc );
224}
225
226//==============================================================================
227Any SAL_CALL getCaughtException()
228{
229 Mapping cpp2uno(Environment::getCurrent(), Environment(OUSTR(UNO_LB_UNO)::rtl::OUString( (&("uno")[0]), ((sal_Int32)((sizeof ("uno"
) / sizeof (("uno")[0]))-1)), (((rtl_TextEncoding) 11)) )
));
230 if (! cpp2uno.is())
231 {
232 throw RuntimeException(
233 OUSTR("cannot get C++ to binary UNO mapping!")::rtl::OUString( (&("cannot get C++ to binary UNO mapping!"
)[0]), ((sal_Int32)((sizeof ("cannot get C++ to binary UNO mapping!"
) / sizeof (("cannot get C++ to binary UNO mapping!")[0]))-1)
), (((rtl_TextEncoding) 11)) )
,
234 Reference< XInterface >() );
235 }
236 Mapping uno2cpp(Environment(OUSTR(UNO_LB_UNO)::rtl::OUString( (&("uno")[0]), ((sal_Int32)((sizeof ("uno"
) / sizeof (("uno")[0]))-1)), (((rtl_TextEncoding) 11)) )
), Environment::getCurrent());
237 if (! uno2cpp.is())
238 {
239 throw RuntimeException(
240 OUSTR("cannot get binary UNO to C++ mapping!")::rtl::OUString( (&("cannot get binary UNO to C++ mapping!"
)[0]), ((sal_Int32)((sizeof ("cannot get binary UNO to C++ mapping!"
) / sizeof (("cannot get binary UNO to C++ mapping!")[0]))-1)
), (((rtl_TextEncoding) 11)) )
,
241 Reference< XInterface >() );
242 }
243
244 typelib_TypeDescription * pTD = 0;
245 TYPELIB_DANGER_GET({ typelib_TypeDescriptionReference * pMacroTypeRef = (ExceptionThrower
::getCppuType().getTypeLibType()); typelib_TypeDescription **
ppMacroTypeDescr = (&pTD); if (((pMacroTypeRef->eTypeClass
) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef->
eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE)) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); } else if (!pMacroTypeRef
->pType || !pMacroTypeRef->pType->pWeakRef) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release
( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef
->pType; } }
246 &pTD, ExceptionThrower::getCppuType().getTypeLibType() ){ typelib_TypeDescriptionReference * pMacroTypeRef = (ExceptionThrower
::getCppuType().getTypeLibType()); typelib_TypeDescription **
ppMacroTypeDescr = (&pTD); if (((pMacroTypeRef->eTypeClass
) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef->
eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE)) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); } else if (!pMacroTypeRef
->pType || !pMacroTypeRef->pType->pWeakRef) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release
( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef
->pType; } }
;
247
248 UnoInterfaceReference unoI;
249 cpp2uno.mapInterface(
250 reinterpret_cast< void ** >( &unoI.m_pUnoI ),
251 static_cast< XExceptionThrower * >( &theExceptionThrower::get() ), pTD );
252 OSL_ASSERT( unoI.is() )do { if (true && (!(unoI.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppuhelper/source/exc_thrower.cxx"
":" "252" ": "), "OSL_ASSERT: %s", "unoI.is()"); } } while (
false)
;
253
254 typelib_TypeDescription * pMemberTD = 0;
255 TYPELIB_DANGER_GET({ typelib_TypeDescriptionReference * pMacroTypeRef = (reinterpret_cast
< typelib_InterfaceTypeDescription * >( pTD )-> ppMembers
[ 1 ]); typelib_TypeDescription ** ppMacroTypeDescr = (&pMemberTD
); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr
, pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef
->pType->pWeakRef) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release
( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef
->pType; } }
256 &pMemberTD,{ typelib_TypeDescriptionReference * pMacroTypeRef = (reinterpret_cast
< typelib_InterfaceTypeDescription * >( pTD )-> ppMembers
[ 1 ]); typelib_TypeDescription ** ppMacroTypeDescr = (&pMemberTD
); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr
, pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef
->pType->pWeakRef) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release
( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef
->pType; } }
257 reinterpret_cast< typelib_InterfaceTypeDescription * >( pTD )->{ typelib_TypeDescriptionReference * pMacroTypeRef = (reinterpret_cast
< typelib_InterfaceTypeDescription * >( pTD )-> ppMembers
[ 1 ]); typelib_TypeDescription ** ppMacroTypeDescr = (&pMemberTD
); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr
, pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef
->pType->pWeakRef) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release
( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef
->pType; } }
258 ppMembers[ 1 ] /* rethrowException() */ ){ typelib_TypeDescriptionReference * pMacroTypeRef = (reinterpret_cast
< typelib_InterfaceTypeDescription * >( pTD )-> ppMembers
[ 1 ]); typelib_TypeDescription ** ppMacroTypeDescr = (&pMemberTD
); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr
, pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef
->pType->pWeakRef) { typelib_typedescriptionreference_getDescription
( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release
( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef
->pType; } }
;
259
260 uno_Any exc_mem;
261 uno_Any * exc = &exc_mem;
262 unoI.dispatch( pMemberTD, 0, 0, &exc );
263
264 TYPELIB_DANGER_RELEASE( pMemberTD ){ if ((((pMemberTD)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| ((pMemberTD)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) typelib_typedescription_release( pMemberTD ); }
;
265 TYPELIB_DANGER_RELEASE( pTD ){ if ((((pTD)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD
|| ((pTD)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE
)) typelib_typedescription_release( pTD ); }
;
266
267 if (exc == 0)
268 {
269 throw RuntimeException(
270 OUSTR("rethrowing C++ exception failed!")::rtl::OUString( (&("rethrowing C++ exception failed!")[0
]), ((sal_Int32)((sizeof ("rethrowing C++ exception failed!")
/ sizeof (("rethrowing C++ exception failed!")[0]))-1)), (((
rtl_TextEncoding) 11)) )
,
271 Reference< XInterface >() );
272 }
273
274 Any ret;
275 uno_any_destruct( &ret, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
276 uno_type_any_constructAndConvert(
277 &ret, exc->pData, exc->pType, uno2cpp.get() );
278 uno_any_destruct( exc, 0 );
279 return ret;
280}
281
282}
283
284/* vim:set shiftwidth=4 softtabstop=4 expandtab: */