INN commit: branches/2.4 (innd/python.c nnrpd/python.c)
INN Commit
Russ_Allbery at isc.org
Sun Jun 22 09:59:11 UTC 2008
Date: Sunday, June 22, 2008 @ 02:59:11
Author: iulius
Revision: 7891
Fix an issue with Python exception handling.
Modified:
branches/2.4/innd/python.c
branches/2.4/nnrpd/python.c
----------------+
innd/python.c | 20 +++++++++++++++++++-
nnrpd/python.c | 21 +++++++++++++++++++--
2 files changed, 38 insertions(+), 3 deletions(-)
Modified: innd/python.c
===================================================================
--- innd/python.c 2008-06-22 09:52:32 UTC (rev 7890)
+++ innd/python.c 2008-06-22 09:59:11 UTC (rev 7891)
@@ -9,6 +9,14 @@
**
** The astute reader may notice the commission of blatant atrocities
** against Python's OO model here. Don't tell Guido.
+**
+** A quick note regarding Python exceptions: functions like
+** PyObject_GetAttrString(PyObject *o, const char *attr_name)
+** raise an exception when they fail, even though they return NULL.
+** And as exceptions accumulate from caller to caller and so on,
+** it generates weird issues with Python scripts afterwards. So such
+** uses should be checked before. For instance with:
+** PyObject_HasAttrString(PyObject *o, const char *attr_name).
*/
#include "config.h"
@@ -570,7 +578,17 @@
char *methname;
{
Py_XDECREF(*methptr);
- *methptr = PyObject_GetAttrString(PYFilterObject, methname);
+
+ /* We check with HasAttrString() the existence of the method because
+ * otherwise, in case it does not exist, an exception is raised by Python,
+ * although the result of the function is NULL. */
+ if (PyObject_HasAttrString(PYFilterObject, (char *) methname) == 1) {
+ /* Get a pointer to given method. */
+ *methptr = PyObject_GetAttrString(PYFilterObject, (char *) methname);
+ } else {
+ *methptr = NULL;
+ }
+
if (*methptr == NULL)
syslog(L_NOTICE, "python method %s not found", methname);
else if (PyCallable_Check(*methptr) == 0) {
Modified: nnrpd/python.c
===================================================================
--- nnrpd/python.c 2008-06-22 09:52:32 UTC (rev 7890)
+++ nnrpd/python.c 2008-06-22 09:59:11 UTC (rev 7891)
@@ -8,6 +8,14 @@
** This code bases on Python work for innd filtering done by
** G.J. Andruk <meowing at banet.net>. Also it borrows some ideas from
** TCL/Perl work done by Bob Heiney and Christophe Wolfhugel.
+**
+** A quick note regarding Python exceptions: functions like
+** PyObject_GetAttrString(PyObject *o, const char *attr_name)
+** raise an exception when they fail, even though they return NULL.
+** And as exceptions accumulate from caller to caller and so on,
+** it generates weird issues with Python scripts afterwards. So such
+** uses should be checked before. For instance with:
+** PyObject_HasAttrString(PyObject *o, const char *attr_name).
*/
#include "config.h"
@@ -608,8 +616,17 @@
methptr = &fp->procs[type][method];
- /* Get a pointer to given method */
- *methptr = PyObject_GetAttrString(PYAuthObject, methname);
+ /*
+ ** We check with HasAttrString() the existence of the method because
+ ** otherwise, in case it does not exist, an exception is raised by Python,
+ ** although the result of the function is NULL.
+ */
+ if (PyObject_HasAttrString(PYAuthObject, (char *) methname) == 1) {
+ /* Get a pointer to given method. */
+ *methptr = PyObject_GetAttrString(PYAuthObject, (char *) methname);
+ } else {
+ *methptr = NULL;
+ }
/* See if such method is defined */
if (*methptr == NULL)
More information about the inn-committers
mailing list