Skip to content

Commit 762bff6

Browse files
committed
Fixed memory corruption in _KeyData
1 parent d05a65d commit 762bff6

File tree

3 files changed

+22
-35
lines changed

3 files changed

+22
-35
lines changed

src/xmlsec.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
#include <xmlsec/xmltree.h>
1+
#include <xmlsec/xmlsec.h>
2+
#include <xmlsec/errors.h>
3+
#include <xmlsec/templates.h>
24
#include <xmlsec/xmldsig.h>
35
#include <xmlsec/xmlenc.h>
4-
#include <xmlsec/templates.h>
5-
#include <xmlsec/errors.h>
6+
#include <xmlsec/xmltree.h>
67
#include <xmlsec/openssl/app.h>
78
#include <xmlsec/openssl/crypto.h>
9+
#include <xmlsec/openssl/x509.h>

src/xmlsec/key.pyx

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -239,29 +239,17 @@ cdef class KeysManager(object):
239239
handle = xmlSecKeysMngrCreate()
240240
if handle == NULL:
241241
raise InternalError("failed to create keys manager", -1)
242+
rv = xmlSecOpenSSLAppDefaultKeysMngrInit(handle)
243+
if rv < 0:
244+
xmlSecKeysMngrDestroy(handle)
245+
raise InternalError("failed to init manager", rv)
246+
242247
self._handle = handle
243248

244249
def __dealloc__(self):
245250
if self._handle != NULL:
246251
xmlSecKeysMngrDestroy(self._handle)
247252

248-
249-
def __ensure_init(self, expected_mode):
250-
if self._mode == expected_mode:
251-
return
252-
253-
if self._mode != 0:
254-
raise InternalError("Cannot use one manager for verify and sign", -1)
255-
256-
if expected_mode == 1:
257-
rv = xmlSecOpenSSLAppDefaultKeysMngrInit(self._handle)
258-
else:
259-
rv = xmlSecOpenSSLKeysMngrInit(self._handle)
260-
261-
if rv < 0:
262-
raise InternalError("failed to initialize keys manager", rv)
263-
264-
265253
def add_key(self, Key key):
266254
"""add (a copy of) *key*."""
267255

@@ -273,7 +261,6 @@ cdef class KeysManager(object):
273261
if key_handle == NULL:
274262
raise InternalError("failed to copy key", -1)
275263

276-
self.__ensure_init(1)
277264
rv = xmlSecOpenSSLAppDefaultKeysMngrAdoptKey(self._handle, key_handle)
278265
if rv < 0:
279266
xmlSecKeyDestroy(key_handle)
@@ -287,7 +274,6 @@ cdef class KeysManager(object):
287274
cdef int rv
288275
cdef const_char* c_filename = <const_char*>_b(filename)
289276

290-
self.__ensure_init(2)
291277
with nogil:
292278
rv = xmlSecOpenSSLAppKeysMngrCertLoad(self._handle, c_filename, format, type)
293279

@@ -308,7 +294,6 @@ cdef class KeysManager(object):
308294
c_size = len(data)
309295
c_data = <const_unsigned_char*><char*>data
310296

311-
self.__ensure_init(2)
312297
with nogil:
313298
rv = xmlSecOpenSSLAppKeysMngrCertLoadMemory(self._handle, c_data, c_size, format, type)
314299

src/xmlsec/utils.pyx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ def init():
1616
This is called upon library import and does not need to be called
1717
again (unless @ref _shutdown is called explicitly).
1818
"""
19-
r = xmlSecInit()
20-
if r != 0:
19+
if xmlSecInit() < 0:
2120
return False
2221

23-
r = xmlSecOpenSSLInit()
24-
if r != 0:
22+
if xmlSecOpenSSLAppInit(NULL) < 0:
23+
xmlSecShutdown()
2524
return False
2625

27-
r = xmlSecOpenSSLAppInit(NULL)
28-
if r != 0:
26+
if xmlSecOpenSSLInit() < 0:
27+
xmlSecOpenSSLAppShutdown()
28+
xmlSecShutdown()
2929
return False
3030

3131
return True
@@ -37,16 +37,16 @@ def shutdown():
3737
This is called automatically upon interpreter termination and
3838
should not need to be called explicitly.
3939
"""
40-
r = xmlSecOpenSSLAppShutdown()
41-
if r != 0:
40+
if xmlSecOpenSSLShutdown() < 0:
4241
return False
4342

44-
r = xmlSecOpenSSLShutdown()
45-
if r != 0:
43+
if xmlSecOpenSSLAppShutdown() < 0:
4644
return False
4745

48-
r = xmlSecShutdown()
49-
return r == 0
46+
if xmlSecShutdown() < 0:
47+
return False
48+
49+
return True
5050

5151

5252
def enable_debug_trace(flag):

0 commit comments

Comments
 (0)