From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Blake Shaw via "Bug reports for GUILE, GNU's Ubiquitous Extension Language" Newsgroups: gmane.lisp.guile.bugs Subject: bug#60928: [PATCH] bugfix/make_hash_table: fix segfault when arg< 0 for make-hash-table Date: Wed, 18 Jan 2023 14:10:22 +0700 Message-ID: <20230118071022.29809-1-blake@reproduciblemedia.com> Reply-To: Blake Shaw Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7639"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Blake Shaw To: 60928@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Wed Jan 18 09:39:27 2023 Return-path: Envelope-to: guile-bugs@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 1pI3yh-0001iG-2w for guile-bugs@m.gmane-mx.org; Wed, 18 Jan 2023 09:39:27 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pI3yS-00020R-1R; Wed, 18 Jan 2023 03:39:12 -0500 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 1pI3yI-0001wo-Qk for bug-guile@gnu.org; Wed, 18 Jan 2023 03:39:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pI3yI-0001be-4W for bug-guile@gnu.org; Wed, 18 Jan 2023 03:39:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pI3yI-0001zi-06 for bug-guile@gnu.org; Wed, 18 Jan 2023 03:39:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Blake Shaw Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 18 Jan 2023 08:39:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 60928 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16740310897598 (code B ref -1); Wed, 18 Jan 2023 08:39:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 18 Jan 2023 08:38:09 +0000 Original-Received: from localhost ([127.0.0.1]:39111 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pI3xP-0001yR-Nd for submit@debbugs.gnu.org; Wed, 18 Jan 2023 03:38:09 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:54778) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pI2bU-00082k-Hy for submit@debbugs.gnu.org; Wed, 18 Jan 2023 02:11:26 -0500 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 1pI2bU-0005DH-Bh for bug-guile@gnu.org; Wed, 18 Jan 2023 02:11:24 -0500 Original-Received: from out2.migadu.com ([188.165.223.204]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pI2bR-000491-Da for bug-guile@gnu.org; Wed, 18 Jan 2023 02:11:24 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=reproduciblemedia.com; s=key1; t=1674025873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=L1d2bWhhtfyAXFwDOMAWDGn8xRvujpqIL6MrQnX7kq0=; b=dhQcDkezj64WBDlKA1k61FVQwH1lJfMP1eTwm61eFpU2mBEj9D84thX110Fz75jfmpTOY+ ZCGOU8aAHorR4PkSfDvV9k0z/zDjXTqHan+O35KAElKMh6Y6MkPTI8v3Fv4euoVYu27O8I i7VP8avmTGVXPv8GEESqWQ51CdXGrT8= X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=188.165.223.204; envelope-from=blake@reproduciblemedia.com; helo=out2.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 18 Jan 2023 03:38:06 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:10524 Archived-At: * libguile/hashtab.c (make_hash_table): FIX SEGMENTATION FAULT Currently on Guix if a user evokes (make-hash-table arg) where arg < 0, guile segfaults. This patch adds the most straight forward solution, checking if the value passed to make-hash-table is less than 0, and if so, throwing an error with scm_out_of_range to avoid segfaulting. It builds and passes all tests in a guix shell using the command: $ guix shell automake autoconf make flex gnulib gettext libtool \ gperf gmp git libffi -D guile guix -C -- \ ./autogen.sh && ./configure && make && make check afterwards, using: ./meta/guile -q => scheme@(guile-user)> (make-hash-table -1) ice-9/boot-9.scm:1685:16: In procedure raise-exception: Value out of range 0 to< 18446744073709551615: -1 as desired... I'm not familiar with the inner workings of libguile, but figured I'd offer a fix regardless, so take this this patch with a grain of salt, it was a quicky... --- libguile/hashtab.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/libguile/hashtab.c b/libguile/hashtab.c index b4f004c1d..9cb5d7a47 100644 --- a/libguile/hashtab.c +++ b/libguile/hashtab.c @@ -84,23 +84,24 @@ make_hash_table (unsigned long k, const char *func_name) SCM vector; scm_t_hashtable *t; int i = 0, n = k ? k : 31; - while (i + 1 < HASHTABLE_SIZE_N && n > hashtable_size[i]) - ++i; - n = hashtable_size[i]; - - vector = scm_c_make_vector (n, SCM_EOL); - - t = scm_gc_malloc_pointerless (sizeof (*t), s_hashtable); - t->min_size_index = t->size_index = i; - t->n_items = 0; - t->lower = 0; - t->upper = 9 * n / 10; + if (k < i) { + scm_out_of_range (func_name, scm_from_ulong (k)); + } else { + while (i + 1 < HASHTABLE_SIZE_N && n > hashtable_size[i]) + ++i; + n = hashtable_size[i]; + vector = scm_c_make_vector (n, SCM_EOL); + t = scm_gc_malloc_pointerless (sizeof (*t), s_hashtable); + t->min_size_index = t->size_index = i; + t->n_items = 0; + t->lower = 0; + t->upper = 9 * n / 10; /* FIXME: we just need two words of storage, not three */ - return scm_double_cell (scm_tc7_hashtable, SCM_UNPACK (vector), - (scm_t_bits)t, 0); + return scm_double_cell (scm_tc7_hashtable, SCM_UNPACK (vector), + (scm_t_bits)t, 0); + } } - void scm_i_rehash (SCM table, scm_t_hash_fn hash_fn, -- 2.38.1