]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
improve exception handling. Helps with #5242
authorAlan T. DeKok <aland@freeradius.org>
Thu, 7 Dec 2023 14:24:42 +0000 (09:24 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 16 Feb 2024 21:22:46 +0000 (16:22 -0500)
so that no python exceptions remain after the do_python_single call.
Otherwise the next request will immediately fail.

Patch from #5242, but separated out to keep commit history
a little clearer.

src/modules/rlm_python3/rlm_python3.c

index aaa43ab73d7d47b87cb1cad7b969fae90a0d32bc..e6f82d01987f515e306c7211572573258647b01f 100644 (file)
@@ -387,6 +387,7 @@ static int mod_populate_vptuple(PyObject *pPair, VALUE_PAIR *vp)
                ERROR("%s:%d, vp->da->name: %s", __func__, __LINE__, vp->da->name);
                if (PyErr_Occurred()) {
                        python_error_log();
+                       PyErr_Clear();
                }
                
                return -1;
@@ -567,6 +568,7 @@ static rlm_rcode_t do_python_single(REQUEST *request, PyObject *pFunc, char cons
                ERROR("%s:%d, %s - pRet is NULL", __func__, __LINE__, funcname);
                if (PyErr_Occurred()) {
                        python_error_log();
+                       PyErr_Clear();
                }
                ret = RLM_MODULE_FAIL;
                goto finish;
@@ -674,6 +676,13 @@ finish:
        if (ret == RLM_MODULE_FAIL) {
                ERROR("%s:%d, %s - RLM_MODULE_FAIL", __func__, __LINE__, funcname);
        }
+
+       if (PyErr_Occurred()) {
+               ERROR("Unhandled Python exception (see below); clearing.");
+               python_error_log();
+               PyErr_Clear();
+       }
+
        return ret;
 }