guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 7/8] HashSplitter_init: guard against bits/fanbits overflow


From: Rob Browning
Subject: [PATCH 7/8] HashSplitter_init: guard against bits/fanbits overflow
Date: Tue, 30 May 2023 19:49:43 -0500

Replace PyArg_ParseTuple "I" conversion (which ignores overflow) with
bup_uint_from_py.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
---
 lib/bup/_hashsplit.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/lib/bup/_hashsplit.c b/lib/bup/_hashsplit.c
index ade413181..02798708f 100644
--- a/lib/bup/_hashsplit.c
+++ b/lib/bup/_hashsplit.c
@@ -31,6 +31,7 @@
 
 #include "_hashsplit.h"
 #include "bup/intprops.h"
+#include "bup/pyutil.h"
 #include "bupsplit.h"
 
 #if defined(FS_IOC_GETFLAGS) && defined(FS_IOC_SETFLAGS)
@@ -294,11 +295,11 @@ static int HashSplitter_init(HashSplitter *self, PyObject 
*args, PyObject *kwds)
         "fanbits",
         NULL
      };
-    PyObject *files = NULL;
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OI|OpI", argnames,
-                                     &files, &self->bits,
+    PyObject *files = NULL, *py_bits = NULL, *py_fanbits = NULL;
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|OpO", argnames,
+                                     &files, &py_bits,
                                      &self->progress, &self->boundaries,
-                                     &self->fanbits))
+                                     &py_fanbits))
         goto error;
 
     self->files = PyObject_GetIter(files);
@@ -311,6 +312,8 @@ static int HashSplitter_init(HashSplitter *self, PyObject 
*args, PyObject *kwds)
     else
         Py_INCREF(self->progress);
 
+    if(py_bits && !bup_uint_from_py(&self->bits, py_bits, 
"HashSplitter(bits)"))
+        goto error;
     if (self->bits < 13 || self->bits > max_bits) {
         PyErr_Format(PyExc_ValueError,
                      "invalid bits value %d (must be in [%d, %d])",
@@ -318,6 +321,9 @@ static int HashSplitter_init(HashSplitter *self, PyObject 
*args, PyObject *kwds)
         goto error;
     }
 
+    if(py_fanbits && !bup_uint_from_py(&self->fanbits, py_fanbits,
+                                       "HashSplitter(fanbits)"))
+        goto error;
     if (!self->fanbits) {
         PyErr_Format(PyExc_ValueError, "fanbits must be non-zero");
         goto error;
-- 
2.39.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]