s3/libsmb/py: match input argument types with C types
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 7 Feb 2019 04:04:43 +0000 (17:04 +1300)
committerNoel Power <npower@samba.org>
Fri, 8 Feb 2019 12:31:38 +0000 (13:31 +0100)
If PyArg_ParseTupleAndKeywords() is given, say, an "H" format (meaning
unsigned short int) but the referenced variable is a plain unsigned
int, the top 16 bits of the variable will be left undefined. In that
case we should use an "I" format (and/or initialize the variable).

In many cases the change is fairly innocuous, such as when "i" and "I"
are mixed (for signed and unsigned ints respectively), but the
resulting write is the same size and probably gives the same result in
practice.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Noel Power <npower@samba.org>
source3/libsmb/pylibsmb.c

index 5f3e6a8c724ac1a681778925997485e443f04bcd..da2e5e12d0d64ba9acc218e39763c77bfda4bc7e 100644 (file)
@@ -856,7 +856,7 @@ static PyObject *py_cli_write(struct py_cli_state *self, PyObject *args,
                "fnum", "buffer", "offset", "mode", NULL };
 
        if (!ParseTupleAndKeywords(
-                   args, kwds, "I" PYARG_BYTES_LEN "K|I", kwlist,
+                   args, kwds, "i" PYARG_BYTES_LEN "K|I", kwlist,
                    &fnum, &buf, &buflen, &offset, &mode)) {
                return NULL;
        }
@@ -1012,7 +1012,7 @@ static PyObject *py_cli_read(struct py_cli_state *self, PyObject *args,
                "fnum", "offset", "size", NULL };
 
        if (!ParseTupleAndKeywords(
-                   args, kwds, "IKI", kwlist, &fnum, &offset,
+                   args, kwds, "iKI", kwlist, &fnum, &offset,
                    &size)) {
                return NULL;
        }
@@ -1230,7 +1230,7 @@ static PyObject *py_cli_list(struct py_cli_state *self,
        PyObject *result = NULL;
        const char *kwlist[] = { "directory", "mask", "attribs", NULL };
 
-       if (!ParseTupleAndKeywords(args, kwds, "z|sH:list", kwlist,
+       if (!ParseTupleAndKeywords(args, kwds, "z|sI:list", kwlist,
                                   &base_dir, &user_mask, &attribute)) {
                return NULL;
        }