From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Rob Browning Newsgroups: gmane.lisp.guile.devel Subject: [PATCH 7/8] HashSplitter_init: guard against bits/fanbits overflow Date: Tue, 30 May 2023 19:49:43 -0500 Message-ID: <20230531004944.1657633-8-rlb@defaultvalue.org> References: <20230531004944.1657633-1-rlb@defaultvalue.org> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17868"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Wed May 31 02:50:56 2023 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q4A3E-0004RF-CY for guile-devel@m.gmane-mx.org; Wed, 31 May 2023 02:50:56 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4A2G-0006Mk-9Z; Tue, 30 May 2023 20:49:56 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4A2C-0006LX-Q8 for guile-devel@gnu.org; Tue, 30 May 2023 20:49:52 -0400 Original-Received: from defaultvalue.org ([45.33.119.55]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4A29-0008Ek-Nm for guile-devel@gnu.org; Tue, 30 May 2023 20:49:52 -0400 Original-Received: from trouble.defaultvalue.org (localhost [127.0.0.1]) (Authenticated sender: rlb@defaultvalue.org) by defaultvalue.org (Postfix) with ESMTPSA id 290962069B for ; Tue, 30 May 2023 19:49:46 -0500 (CDT) Original-Received: by trouble.defaultvalue.org (Postfix, from userid 1000) id 1E73B14E0AB; Tue, 30 May 2023 19:49:45 -0500 (CDT) X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531004944.1657633-1-rlb@defaultvalue.org> Received-SPF: pass client-ip=45.33.119.55; envelope-from=rlb@defaultvalue.org; helo=defaultvalue.org X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:21845 Archived-At: Replace PyArg_ParseTuple "I" conversion (which ignores overflow) with bup_uint_from_py. Signed-off-by: Rob Browning Tested-by: Rob Browning --- 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