Skip to content

Commit

Permalink
use errno in a safer way
Browse files Browse the repository at this point in the history
  • Loading branch information
stroeder committed Apr 25, 2017
1 parent 29d6ee1 commit 5e86ba0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
----------------------------------------------------------------
Released 2.4.34 2017-04-xx

Modules/
* use errno in a safer way

----------------------------------------------------------------
Released 2.4.33 2017-04-25

Expand Down Expand Up @@ -1358,4 +1361,4 @@ Released 2.0.0pre02 2002-02-01
----------------------------------------------------------------
Released 1.10alpha3 2000-09-19

$Id: CHANGES,v 1.418 2017/04/25 11:20:40 stroeder Exp $
$Id: CHANGES,v 1.419 2017/04/25 12:45:27 stroeder Exp $
11 changes: 7 additions & 4 deletions Modules/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* errors that arise from ldap use
* Most errors become their own exception
* See http://www.python-ldap.org/ for details.
* $Id: errors.c,v 1.28 2017/04/24 18:32:51 stroeder Exp $ */
* $Id: errors.c,v 1.29 2017/04/25 12:45:27 stroeder Exp $ */

#include "common.h"
#include "errors.h"
Expand Down Expand Up @@ -54,11 +54,14 @@ LDAPerror( LDAP *l, char *msg )
return NULL;
}
else {
int errnum, opt_errnum;
int myerrno, errnum, opt_errnum;
PyObject *errobj;
PyObject *info;
PyObject *str;

/* at first save errno for later use before it gets overwritten by another call */
myerrno = errno;

char *matched, *error;

opt_errnum = ldap_get_option(l, LDAP_OPT_ERROR_NUMBER, &errnum);
Expand Down Expand Up @@ -104,8 +107,8 @@ LDAPerror( LDAP *l, char *msg )
if (str)
PyDict_SetItemString( info, "info", str );
Py_XDECREF(str);
} else if (errno != 0) {
str = PyString_FromString(strerror(errno));
} else if (myerrno != 0) {
str = PyString_FromString(strerror(myerrno));
if(str)
PyDict_SetItemString( info, "info", str);
Py_XDECREF(str);
Expand Down

0 comments on commit 5e86ba0

Please sign in to comment.