Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error handling to Python API calls in LDAPraise_for_message #341

Open
wants to merge 1 commit into
base: master
from

Conversation

@encukou
Copy link
Member

encukou commented Jun 5, 2020

Add CPython style error handling to LDAPraise_for_message: ensure pointers are set to NULL when freed, and free all non-NULL pointers at the end. Use goto to jump to the cleanup. (The label is usually called error, which here clashes with a variable name).

Note that Python API sets the current exception on failure. If something else than C API fails, PyErr_NoMemory or PyErr_SetObject is called before returning NULL.

I recommend reviewing the diff with whitespace changes hidden (-w in Git CLI, ?w=1 in GitHub URLs).

@codecov
Copy link

codecov bot commented Jun 5, 2020

Codecov Report

Merging #341 into master will decrease coverage by 2.73%.
The diff coverage is 50.41%.

@@            Coverage Diff             @@
##           master     #341      +/-   ##
==========================================
- Coverage   71.03%   68.29%   -2.74%     
==========================================
  Files          49       49              
  Lines        4833     4861      +28     
  Branches      808      820      +12     
==========================================
- Hits         3433     3320     -113     
- Misses       1066     1187     +121     
- Partials      334      354      +20     
Impacted Files Coverage Δ
Modules/constants.c 47.71% <50.41%> (-6.60%) ⬇️
Lib/ldap/compat.py 18.86% <0.00%> (-47.17%) ⬇️
Lib/ldap/functions.py 80.00% <0.00%> (-17.50%) ⬇️
Lib/ldap/ldapobject.py 64.29% <0.00%> (-13.61%) ⬇️
Lib/ldap/__init__.py 76.92% <0.00%> (-13.47%) ⬇️
Lib/ldap/sasl.py 75.00% <0.00%> (-11.12%) ⬇️
Modules/ldapmodule.c 59.09% <0.00%> (-4.91%) ⬇️
Lib/ldap/dn.py 94.23% <0.00%> (-3.85%) ⬇️
Lib/slapdtest/_slapdtest.py 83.21% <0.00%> (-1.79%) ⬇️
Modules/LDAPObject.c 66.94% <0.00%> (+0.42%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3c0f7ef...7067217. Read the comment docs.

@tiran tiran self-assigned this Jun 5, 2020
@tiran
Copy link
Member

tiran commented Jun 5, 2020

It'll review the PR next week or the week after. Too much C code for a Friday afternoon!

@encukou encukou added this to the 3.3 milestone Jun 5, 2020
@tiran tiran modified the milestones: 3.3, future Jun 8, 2020
@encukou encukou removed this from the 3.3 milestone Jun 8, 2020
@@ -51,138 +51,193 @@ LDAPerr(int errnum)
PyObject *
LDAPraise_for_message(LDAP *l, LDAPMessage *m)
{
int myerrno, errnum, opt_errnum, res, msgid = -1, msgtype = 0;
PyObject *errobj = NULL;
PyObject *info;

This comment has been minimized.

@droideck

droideck Aug 5, 2020

Contributor

GCC prints a warning about this line because it is uninitialized.

PyErr_SetObject(errobj, info);
Py_DECREF(info);
ldap_memvfree((void **)refs);
PyErr_SetObject(errobj, info);

This comment has been minimized.

@droideck

droideck Aug 5, 2020

Contributor

I get a segfault here:

test105_reconnect_restore (Tests.t_ldapobject.Test01_ReconnectLDAPObject) ... make: *** [Makefile:72: valgrind] Segmentation fault (core dumped)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.