BUG/MEDIUM: spoa/python: Fixing PyObject_Call positional arguments
authorGilchrist Dadaglo <dadaglo@amazon.com>
Tue, 8 Dec 2020 14:37:13 +0000 (14:37 +0000)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 14 Dec 2020 10:49:48 +0000 (11:49 +0100)
As per https://docs.python.org/3/c-api/object.html#c.PyObject_Call,
positional arguments should be an empty tuple when not used.
Previously the code had a dictionary instead of tuple. This commit is to
fix it and use tuple to avoid unexpected consequences

This patch must be backported as far as 2.0.

(cherry picked from commit 042f697a0fce0255b569786d29e929a4a41cbc46)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 789fb20542c76e14d68b916efe0dba6b012858b8)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 712c28d00e23f21127eb0c4809e40fc5b19e223b)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

contrib/spoa_server/ps_python.c

index b383680..fa24921 100644 (file)
@@ -29,7 +29,7 @@ static PyObject *module_ipaddress;
 static PyObject *ipv4_address;
 static PyObject *ipv6_address;
 static PyObject *spoa_error;
-static PyObject *empty_array;
+static PyObject *empty_tuple;
 static struct worker *worker;
 
 static int ps_python_start_worker(struct worker *w);
@@ -416,8 +416,8 @@ static int ps_python_start_worker(struct worker *w)
                return 0;
        }
 
-       empty_array = PyDict_New();
-       if (empty_array == NULL) {
+       empty_tuple = PyTuple_New(0);
+       if (empty_tuple == NULL) {
                PyErr_Print();
                return 0;
        }
@@ -601,7 +601,7 @@ static int ps_python_exec_message(struct worker *w, void *ref, int nargs, struct
                                PyErr_Print();
                                return 0;
                        }
-                       value = PyObject_Call(func, empty_array, ip_dict);
+                       value = PyObject_Call(func, empty_tuple, ip_dict);
                        Py_DECREF(func);
                        Py_DECREF(ip_dict);
                        break;
@@ -671,7 +671,7 @@ static int ps_python_exec_message(struct worker *w, void *ref, int nargs, struct
                return 0;
        }
 
-       result = PyObject_Call(python_ref, empty_array, fkw);
+       result = PyObject_Call(python_ref, empty_tuple, fkw);
        Py_DECREF(fkw);
        if (result == NULL) {
                PyErr_Print();