diff options
author | Michal Privoznik <mprivozn@redhat.com> | 2023-02-13 14:45:23 +0100 |
---|---|---|
committer | Michal Privoznik <mprivozn@redhat.com> | 2023-02-13 14:57:13 +0100 |
commit | 3f8aa91db35d1650d8826cf7cc74958954ca0a3f (patch) | |
tree | 2597a594b52ac03093e8ea34a8dbc1e30c3f6ad0 | |
parent | 1c88c411092b73fd36c632af0e5c4bebeae8cdbb (diff) | |
download | libvirt-python-3f8aa91db35d1650d8826cf7cc74958954ca0a3f.tar.gz |
libvirt_virConnectOpenAuth: Avoid plain PyLong_AsLong() call
When constructing the list of credentials to pass to
virConnectOpenAuth(), the virConnectAuth.credtype member is set
via plain PyLong_AsLong() without any error checking. Well, the
code relies on virConnectOpenAuth() to do sanity check of passed
arguments.
Switch to libvirt_intUnwrap() which does check for errors and
avoid needless trip to libvirt's public API upon error.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
-rw-r--r-- | libvirt-override.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libvirt-override.c b/libvirt-override.c index d1a55c5..0aaeb31 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -2012,7 +2012,7 @@ libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; - virConnectPtr c_retval; + virConnectPtr c_retval = NULL; char * name; unsigned int flags; PyObject *pyauth; @@ -2036,7 +2036,8 @@ libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, for (i = 0; i < auth.ncredtype; i++) { PyObject *val; val = PyList_GetItem(pycredtype, i); - auth.credtype[i] = (int)PyLong_AsLong(val); + if (libvirt_intUnwrap(val, &auth.credtype[i]) < 0) + goto cleanup; } } if (pycredcb && pycredcb != Py_None) @@ -2047,6 +2048,7 @@ libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, c_retval = virConnectOpenAuth(name, &auth, flags); LIBVIRT_END_ALLOW_THREADS; + cleanup: VIR_FREE(auth.credtype); py_retval = libvirt_virConnectPtrWrap((virConnectPtr) c_retval); return py_retval; |