Skip to content

Commit c86b8e9

Browse files
tiranencukou
authored andcommitted
Fix error handling of LDAPControl_to_List() (python-ldap#89)
LDAPControls_to_List() may have returned a partly filled list in case Py_BuildValue() fails. In case of an error, DECREF the list and return NULL. python-ldap#89 Closes: python-ldap#22 Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent 18f98aa commit c86b8e9

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Modules/
3434
* Fix reference leak in result4
3535
* Fix several compiler warnings
3636
* Fix memory leak in whoami
37+
* Fix internal error handling of LDAPControl_to_List()
3738
and, thanks to Michael Ströder:
3839
* removed unused code schema.c
3940
* moved code from version.c to ldapmodule.c

Modules/ldapcontrol.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,21 @@ LDAPControls_to_List(LDAPControl **ldcs)
172172
if (tmp)
173173
while (*tmp++) num_ctrls++;
174174

175-
if (!(res = PyList_New(num_ctrls)))
176-
goto endlbl;
175+
if ((res = PyList_New(num_ctrls)) == NULL) {
176+
return NULL;
177+
}
177178

178179
for (i = 0; i < num_ctrls; i++) {
179-
if (!(pyctrl = Py_BuildValue("sbO&", ldcs[i]->ldctl_oid,
180-
ldcs[i]->ldctl_iscritical,
181-
LDAPberval_to_object,
182-
&ldcs[i]->ldctl_value))) {
183-
goto endlbl;
180+
pyctrl = Py_BuildValue("sbO&",
181+
ldcs[i]->ldctl_oid,
182+
ldcs[i]->ldctl_iscritical,
183+
LDAPberval_to_object, &ldcs[i]->ldctl_value);
184+
if (pyctrl == NULL) {
185+
Py_DECREF(res);
186+
return NULL;
184187
}
185188
PyList_SET_ITEM(res, i, pyctrl);
186189
}
187-
Py_INCREF(res);
188-
189-
endlbl:
190-
Py_XDECREF(res);
191190
return res;
192191
}
193192

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy