FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add error handling to Python API calls in LDAPraise_for_message by encukou · Pull Request #341 · python-ldap/python-ldap · GitHub

Add error handling to Python API calls in LDAPraise_for_message - #341

Open
encukou wants to merge 1 commit into
python-ldap:mainfrom
encukou:exceptions
Open

Add error handling to Python API calls in LDAPraise_for_message#341
encukou wants to merge 1 commit into
python-ldap:mainfrom
encukou:exceptions

Conversation

encukou commented Jun 5, 2020

Copy link
Copy Markdown
Member

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 Bot commented Jun 5, 2020
edited
Loading

Copy link
Copy Markdown

Codecov Report

Merging #341 (7067217) into master (39ea8e5) will decrease coverage by 3.01%.
The diff coverage is 50.41%.

❗ Current head 7067217 differs from pull request most recent head 43e8e75. Consider uploading reports for the commit 43e8e75 to get more accurate results

@@            Coverage Diff             @@
##           master     #341      +/-   ##
==========================================
- Coverage   71.30%   68.29%   -3.02%     
==========================================
  Files          50       49       -1     
  Lines        4796     4861      +65     
  Branches      802      820      +18     
==========================================
- Hits         3420     3320     -100     
- Misses       1045     1187     +142     
- Partials      331      354      +23     
Impacted Files Coverage Δ
Modules/constants.c 47.71% <50.41%> (-5.80%) ⬇️
Lib/ldap/compat.py 18.86% <0.00%> (-48.41%) ⬇️
Lib/ldap/cidict.py 69.23% <0.00%> (-27.27%) ⬇️
Lib/ldap/functions.py 80.00% <0.00%> (-17.50%) ⬇️
Lib/ldap/ldapobject.py 64.29% <0.00%> (-15.94%) ⬇️
Lib/ldap/__init__.py 76.92% <0.00%> (-13.47%) ⬇️
Lib/ldap/extop/__init__.py 55.55% <0.00%> (-12.87%) ⬇️
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%) ⬇️
... and 11 more

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 d9ded15...43e8e75. Read the comment docs.

tiran self-assigned this Jun 5, 2020

tiran commented Jun 5, 2020

Copy link
Copy Markdown
Member

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

encukou added this to the 3.3 milestone Jun 5, 2020
tiran modified the milestones: 3.3, future Jun 8, 2020
encukou removed this from the 3.3 milestone Jun 8, 2020
Comment thread Modules/constants.c Outdated
Comment thread Modules/constants.c
PyErr_SetObject(errobj, info);
Py_DECREF(info);
ldap_memvfree((void **)refs);
PyErr_SetObject(errobj, info);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I get a segfault here:

test105_reconnect_restore (Tests.t_ldapobject.Test01_ReconnectLDAPObject) ... make: *** [Makefile:72: valgrind] Segmentation fault (core dumped)

…_message

- Ensure pointers are set to NULL when freed.
- Free all non-NULL pointers at the end.
- Use goto to jump to the cleanup.

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).
Comment thread Modules/constants.c
if (m != NULL) {
msgid = ldap_msgid(m);
msgtype = ldap_msgtype(m);
ldap_parse_result(l, m, &errnum, &matched, &error, &refs,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The function call is missing an error check:

Upon success LDAP_SUCCESS is returned. Otherwise the values of the result parameters are undefined.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Does that mean they should not be freed, like this?

            opt_errnum = ldap_parse_result(l, m, &errnum, &matched, &error,
                                           &refs, &serverctrls, 1);
            if (opt_errnum != LDAP_SUCCESS) {
                // values of the result parameters are undefined; zero them
                matched = NULL;
                error = NULL;
                refs = NULL;
                serverctrls = NULL;
                errnum = opt_errnum;
            }

encukou mentioned this pull request Sep 17, 2021
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL