diff --git a/plugins/python/pyhelpers.c b/plugins/python/pyhelpers.c index 6b235f3df..8fbf0f80a 100644 --- a/plugins/python/pyhelpers.c +++ b/plugins/python/pyhelpers.c @@ -212,7 +212,7 @@ py_str_array_from_tuple(PyObject *py_tuple) Py_ssize_t tuple_size = PyTuple_Size(py_tuple); // we need an extra 0 at the end - char **result = calloc(Py_SSIZE2SIZE(tuple_size) + 1, sizeof(char*)); + char **result = calloc(tuple_size + 1, sizeof(char *)); if (result == NULL) { debug_return_ptr(NULL); } diff --git a/plugins/python/pyhelpers.h b/plugins/python/pyhelpers.h index 01843d7dc..524b14e3b 100644 --- a/plugins/python/pyhelpers.h +++ b/plugins/python/pyhelpers.h @@ -52,7 +52,6 @@ struct PythonContext extern struct PythonContext py_ctx; #define Py_TYPENAME(object) (object ? Py_TYPE(object)->tp_name : "NULL") -#define Py_SSIZE2SIZE(value) ((value) < 0 ? 0 : (size_t)(value)) #define py_sudo_log(...) py_ctx.sudo_log(__VA_ARGS__) diff --git a/plugins/python/python_convmessage.c b/plugins/python/python_convmessage.c index 67e6d96bc..14283dcd7 100644 --- a/plugins/python/python_convmessage.c +++ b/plugins/python/python_convmessage.c @@ -137,7 +137,7 @@ sudo_module_ConvMessages_to_c(PyObject *py_tuple, Py_ssize_t *num_msgs, struct s debug_return_int(SUDO_RC_ERROR); } - *msgs = calloc(Py_SSIZE2SIZE(*num_msgs), sizeof(struct sudo_conv_message)); + *msgs = calloc(*num_msgs, sizeof(struct sudo_conv_message)); if (*msgs == NULL) { debug_return_int(SUDO_RC_ERROR); } diff --git a/plugins/python/sudo_python_module.c b/plugins/python/sudo_python_module.c index bd189df9a..897d471fc 100644 --- a/plugins/python/sudo_python_module.c +++ b/plugins/python/sudo_python_module.c @@ -346,11 +346,12 @@ python_sudo_conversation(PyObject *Py_UNUSED(self), PyObject *py_args, PyObject goto cleanup; } + /* sudo_module_ConvMessages_to_c() returns error if no messages. */ if (sudo_module_ConvMessages_to_c(py_args, &num_msgs, &msgs) < 0) { goto cleanup; } - replies = calloc(Py_SSIZE2SIZE(num_msgs), sizeof(struct sudo_conv_reply)); + replies = calloc(num_msgs, sizeof(struct sudo_conv_reply)); if (replies == NULL) goto cleanup; py_result = PyTuple_New(num_msgs);