From f86d65117ba0c964c64fb58b5a6845561156819c Mon Sep 17 00:00:00 2001 From: Joseph Sutton Date: Fri, 8 Dec 2023 15:58:32 +1300 Subject: [PATCH] s4:libcli: Fix conversion from HRESULT and WERROR to Python objects MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The inner values of HRESULT and WERROR are 32‐bit unsigned integers, which might not be representable in type ‘int’. We must then use the ‘k’ format specifier, which corresponds to ‘unsigned long’, a type guaranteed to be at least 32 bits in size. Commit c81aff362fe99a65385c6f8337ffcb47c9456829 fixed PyErr_FromNTSTATUS(), but it did not attempt to fix the other cases. PyErr_FromHRESULT() might return a tuple like this: (-2147024809, 'One or more arguments are invalid.') which, after this commit, will become this: (2147942487, 'One or more arguments are invalid.') Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- source4/libcli/util/pyerrors.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source4/libcli/util/pyerrors.h b/source4/libcli/util/pyerrors.h index 2eec8c8293f..69110ca2732 100644 --- a/source4/libcli/util/pyerrors.h +++ b/source4/libcli/util/pyerrors.h @@ -20,11 +20,11 @@ #ifndef __PYERRORS_H__ #define __PYERRORS_H__ -#define PyErr_FromWERROR(err) Py_BuildValue("(i,s)", W_ERROR_V(err), discard_const_p(char, win_errstr(err))) +#define PyErr_FromWERROR(err) Py_BuildValue("(k,s)", (unsigned long)(W_ERROR_V(err)), discard_const_p(char, win_errstr(err))) -#define PyErr_FromHRESULT(err) Py_BuildValue("(i,s)", HRES_ERROR_V(err), discard_const_p(char, hresult_errstr_const(err))) +#define PyErr_FromHRESULT(err) Py_BuildValue("(k,s)", (unsigned long)(HRES_ERROR_V(err)), discard_const_p(char, hresult_errstr_const(err))) -#define PyErr_FromNTSTATUS(status) Py_BuildValue("(I,s)", NT_STATUS_V(status), discard_const_p(char, get_friendly_nt_error_msg(status))) +#define PyErr_FromNTSTATUS(status) Py_BuildValue("(k,s)", (unsigned long)(NT_STATUS_V(status)), discard_const_p(char, get_friendly_nt_error_msg(status))) #define PyErr_FromString(str) Py_BuildValue("(s)", discard_const_p(char, str)) @@ -46,17 +46,17 @@ #define PyErr_SetWERROR_and_string(werr, string) \ PyErr_SetObject(PyObject_GetAttrString(PyImport_ImportModule("samba"),\ "WERRORError"), \ - Py_BuildValue("(i,s)", W_ERROR_V(werr), string)) + Py_BuildValue("(k,s)", (unsigned long)(W_ERROR_V(werr)), string)) #define PyErr_SetHRESULT_and_string(hresult, string) \ PyErr_SetObject(PyObject_GetAttrString(PyImport_ImportModule("samba"),\ "HRESULTError"), \ - Py_BuildValue("(i,s)", HRES_ERROR_V(hresult), string)) + Py_BuildValue("(k,s)", (unsigned long)(HRES_ERROR_V(hresult)), string)) #define PyErr_SetNTSTATUS_and_string(status, string) \ PyErr_SetObject(PyObject_GetAttrString(PyImport_ImportModule("samba"),\ "NTSTATUSError"), \ - Py_BuildValue("(i,s)", NT_STATUS_V(status), string)) + Py_BuildValue("(k,s)", (unsigned long)(NT_STATUS_V(status)), string)) #define PyErr_NTSTATUS_IS_ERR_RAISE(status) \ if (NT_STATUS_IS_ERR(status)) { \ -- 2.11.4.GIT