Skip to content

Commit 12e88c3

Browse files
committed
Zero the CB structure at allocation time
Also only set structure members if the corresponding python variable is not None, avoid using GSS_C_AF_NULLADDR by default as address values are protocol dependent, only the caller knows what is the convention for each application protocol. Signed-off-by: Simo Sorce <[email protected]>
1 parent 90de1d7 commit 12e88c3

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

gssapi/raw/chan_bindings.pyx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from libc.stdlib cimport malloc, free
1+
from libc.stdlib cimport calloc, free
22

33
from gssapi.raw.cython_types cimport *
44

@@ -25,34 +25,24 @@ cdef class ChannelBindings:
2525

2626
cdef gss_channel_bindings_t __cvalue__(ChannelBindings self) except NULL:
2727
cdef gss_channel_bindings_t res
28-
res = <gss_channel_bindings_t>malloc(sizeof(res[0]))
28+
res = <gss_channel_bindings_t>calloc(1, sizeof(gss_channel_bindings_t))
2929

30-
if self.initiator_address_type is None:
31-
res.initiator_addrtype = GSS_C_AF_NULLADDR
32-
else:
30+
if self.initiator_address_type is not None:
3331
res.initiator_addrtype = self.initiator_address_type
3432

3533
if self.initiator_address is not None:
3634
res.initiator_address.value = self.initiator_address
3735
res.initiator_address.length = len(self.initiator_address)
38-
else:
39-
res.initiator_address.length = 0
4036

41-
if self.acceptor_address_type is None:
42-
res.acceptor_addrtype = GSS_C_AF_NULLADDR
43-
else:
37+
if self.acceptor_address_type is not None:
4438
res.acceptor_addrtype = self.acceptor_address_type
4539

4640
if self.acceptor_address is not None:
4741
res.acceptor_address.value = self.acceptor_address
4842
res.acceptor_address.length = len(self.acceptor_address)
49-
else:
50-
res.acceptor_address.length = 0
5143

5244
if self.application_data is not None:
5345
res.application_data.value = self.application_data
5446
res.application_data.length = len(self.application_data)
55-
else:
56-
res.application_data.length = 0
5747

5848
return res

0 commit comments

Comments
 (0)