From nobody Wed Apr 2 15:14:49 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4ZST1j3Ff9z5sQ3r; Wed, 02 Apr 2025 15:14:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZST1j2fz3z3gMS; Wed, 02 Apr 2025 15:14:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1743606889; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qCfEbRJ1oXBIgdCsQJ3XHY59MyVKGCc3aAEQG7oIx+Q=; b=GBa4xENWD72yrxhsPO5Gu94ziWwXP+mV5glD0N9LPyxMg7ehRcByXUUXZh3PF+8eCkFnUG vAefkVJBfPTryCTla/Rd7ioD0DQAu53lIpEJ5IiDu1yhKb167p6Q62+1BLS8Y41wv5DONS uQjRpZusLtHgzAepirnyzh7WAxPfH87edwiwZH/YQUq0oU/mbQKQ96cNR5O297rFhpUXn9 uImeHocKap3rmsHE3VXtHAewSsWi9WeGoQX6n7syrBY4kF3hNe7KJdNwuGRtuH+FY3OTK/ NiviLlSwqIfxnoTMlCLZKzEgE7qkmKENcgjtgUIY7BEYoUB53PzVLjh33eKgrw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1743606889; a=rsa-sha256; cv=none; b=Us8oRjm40oefiwiDtLuRBbww05pT35IypctWpViYDWee/ubUj/DqXpO66WZ3MGk1nFxuJl b0JVtbfxpz0HF7WanAqSAFCA/mOQOznErhEj2Sj68KSfiZlCdOPJ+7F8bI2DMYfYycihhF Q6YPOc0uAtwZWeqae0rzIaRke2V6QfpHz5Es01PNDNsQfgghV+0DVI9pzdwG1s1R90ssjP hyWoEhBp2Hy1KOVaTufWZTRLwZr9XCSAwr2q5HaSjKDEnC0HLByONGljuWGInnH71iUYgE J1ksAUfEKqp0FwTNFhorJUjLr8HDfm9JU0GxL68Z11xIgCg6WzYpkcSqV7BdTA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1743606889; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qCfEbRJ1oXBIgdCsQJ3XHY59MyVKGCc3aAEQG7oIx+Q=; b=IoqKe0gfkFdVH8FjZhmwfC1PGexElzF+HDl30oFTqeJhlVEmt9lWjhPQH1m/qcl9fZREAA WA6NA5mcp2tHlwlRyXCNS85tF8j1mXgnoZz67ezn+CulcAEjgJNWwpQta7khYIMaUo2Xr7 8msd65MagCOSfUi+ouRy8HcHS4xDCbEvBYj2TPETt8uObr0qlDV9gZ3jX2H1f9lBqRJRFl +xT5KuhtvP+t/c3hU6LgOxx5eDF8007A9is36ZRXsA5Gx/wRVBZHZP487HVrJ0ll/2JYwv 88CFgTEohatdQyIf+IQegbJ11OAOzTm4UbLZD7Jc+s5m4lcSzhACPCvV1bL/8w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4ZST1j22PMz6NY; Wed, 02 Apr 2025 15:14:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 532FEnll061373; Wed, 2 Apr 2025 15:14:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 532FEnJt061370; Wed, 2 Apr 2025 15:14:49 GMT (envelope-from git) Date: Wed, 2 Apr 2025 15:14:49 GMT Message-Id: <202504021514.532FEnJt061370@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 1cbe8781642e - stable/14 - libdtrace: Fix an off-by-one in the priority queue implementation List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 1cbe8781642e0dc961838b87793ffb145f70719a Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=1cbe8781642e0dc961838b87793ffb145f70719a commit 1cbe8781642e0dc961838b87793ffb145f70719a Author: Mark Johnston AuthorDate: 2025-03-10 03:00:42 +0000 Commit: Mark Johnston CommitDate: 2025-04-02 15:14:36 +0000 libdtrace: Fix an off-by-one in the priority queue implementation The zero'th index in the array is unused, so a priority queue of N elements needs N+1 array slots. Fix the allocation. Also fix the assertion in dt_pq_insert(): the assertion needs to be checked after incrementing the count of items in the priority queue, otherwise it can miss an overflow. Reported by: CHERI MFC after: 2 weeks Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D49242 (cherry picked from commit 7ee1bdd094d376fdc547e8ca33e472f1d37a7d79) --- cddl/contrib/opensolaris/lib/libdtrace/common/dt_pq.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pq.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pq.c index 0cd556abd8f5..ffbac8b6ea1e 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pq.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pq.c @@ -37,7 +37,7 @@ dt_pq_init(dtrace_hdl_t *dtp, uint_t size, dt_pq_value_f value_cb, void *cb_arg) if ((p = dt_zalloc(dtp, sizeof (dt_pq_t))) == NULL) return (NULL); - p->dtpq_items = dt_zalloc(dtp, size * sizeof (p->dtpq_items[0])); + p->dtpq_items = dt_zalloc(dtp, (size + 1) * sizeof (p->dtpq_items[0])); if (p->dtpq_items == NULL) { dt_free(dtp, p); return (NULL); @@ -73,9 +73,9 @@ dt_pq_insert(dt_pq_t *p, void *item) { uint_t i; - assert(p->dtpq_last < p->dtpq_size); - i = p->dtpq_last++; + assert(i <= p->dtpq_size); + p->dtpq_items[i] = item; while (i > 1 && dt_pq_getvalue(p, i) < dt_pq_getvalue(p, i / 2)) {