From nobody Sat Nov 30 19:09:12 2024 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 4Y102w5ZKBz5fW5k; Sat, 30 Nov 2024 19:09:12 +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 4Y102w34Qwz4FcP; Sat, 30 Nov 2024 19:09:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732993752; 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=OSLSUPvIKPyYmU+QjaV6VKI6zVC6j82Gx2p09FQsOSs=; b=ewGnH3h1lJC7PyNqGH6xpU02XtCTp2c9FdzJilLwL4hni/b0k3x/VSFR77YgDkj4+tTcyD RPSw5j8uRbK0Ag0VKga0a/eHhYQd927Eyce+jzFL1uQjBTmUTj/IsA+JIKOaq00fC6/o4P FZrI7XBtGQZMb3TmSWpb9EPP6qGATkhGFBkA33/I86+Fd73qivMTHMYdntRv4kUHv6c9y7 nNpaXkAFbBfco034IbH7t62ePmO9N2AUegE+oX5lyfEfNxgVGeFSmh8ZKuo+h2cHEY8IX+ 6nuboq9CneP/N4PHZzjjdj2IZ7QURjhf/y18tHvvOsr5xRRmzptfJX4Xs7yX2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732993752; 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=OSLSUPvIKPyYmU+QjaV6VKI6zVC6j82Gx2p09FQsOSs=; b=RSL+Gz5KhrJr04F7NYXbY8PK72VBZdGTHlKF7nuUtWSpUek67VamQVq8SiHj9dFmbxnyXh t5/nNJ5XE8djheTnWo16OtO0AtHO+7MRgWjIJatWlyxnFaJIGedEO6m2ucJB7crlKalcem Cd4umsm90sGAegTegiWRPqIRaIQ03q5rQQ+bCspC4QKDKcoN45Z9NP5vGN0oY6WiZLd3uB Zk+xT8Es/WWUeXQP9Uq/TF2F5uHYDJGyjQkckIaabUz39i0OIypeZw0D5uKaJb6AC8S7YE BuyLXX2yj/iggKW+CfpHWa0Ke48TthMBCXYD0dHITOIFUQ+BO9JkrbgytiKQ8g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732993752; a=rsa-sha256; cv=none; b=bsV8b4XvBZTEumI9BY7vCz1qKmi2Odmia0q7p7zkzS2pq/XwPmQYoBpHHNzCt6BCZEasSr 1rzBUq3iaGwse0RZEcqdtyilRvxg+XVbYJlebyCVW6AjyRBQT10dzPrhZNt7s/N/L6aaEZ fR8wac9hN/2NYynAu10D/6SCH1QiLl1bG5pYHDpcZi0Qp7l1EPc5W6WuRVw0ccV3drJ+6z H7GQiZJm338EyetchEuWl5WiUwJRvziVYmRZfgunjE8/0j9hH4DCjtFb1y2Td5LbthYFO7 VuNTJigEtz1/FZuqgvSpUUuSXNT8P0qxdsyNVdWYG3g/3ggXDha9sPPtvUh1GA== 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 4Y102w1JHrzKsV; Sat, 30 Nov 2024 19:09:12 +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 4AUJ9Ccl097450; Sat, 30 Nov 2024 19:09:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AUJ9CC4097447; Sat, 30 Nov 2024 19:09:12 GMT (envelope-from git) Date: Sat, 30 Nov 2024 19:09:12 GMT Message-Id: <202411301909.4AUJ9CC4097447@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: a979d6f59919 - stable/13 - pkg: Allocate a suitably-sized string for the local ABI 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: a979d6f59919c734baa2e648de521d56b0da02c4 Auto-Submitted: auto-generated The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=a979d6f59919c734baa2e648de521d56b0da02c4 commit a979d6f59919c734baa2e648de521d56b0da02c4 Author: John Baldwin AuthorDate: 2023-11-16 00:53:53 +0000 Commit: John Baldwin CommitDate: 2024-11-30 18:58:38 +0000 pkg: Allocate a suitably-sized string for the local ABI Previously the local ABI string was written to an on-stack buffer and the pointer to that buffer was saved in a global before the function returned. This had two issues: c[ABI].val pointed to a no-longer-valid on-stack buffer after config_init returned, and the string could potentially be truncated. Fix both of those by changing pkg_get_myabi to return a pointer to a string allocated by asprintf. Note that the allocated string is left in the global config array until it is implicitly freed on process exit. Reported by: GCC 13 -Wdangling-pointer Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D42623 (cherry picked from commit fd9ae9ac04edf9acef4a2ffbf663698a2b8e7ced) --- usr.sbin/pkg/config.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/usr.sbin/pkg/config.c b/usr.sbin/pkg/config.c index a2b005eca835..ce3a11cf8c81 100644 --- a/usr.sbin/pkg/config.c +++ b/usr.sbin/pkg/config.c @@ -144,32 +144,35 @@ static struct config_entry c[] = { } }; -static int -pkg_get_myabi(char *dest, size_t sz) +static char * +pkg_get_myabi(void) { struct utsname uts; char machine_arch[255]; + char *abi; size_t len; int error; error = uname(&uts); if (error) - return (errno); + return (NULL); len = sizeof(machine_arch); error = sysctlbyname("hw.machine_arch", machine_arch, &len, NULL, 0); if (error) - return (errno); + return (NULL); machine_arch[len] = '\0'; /* * Use __FreeBSD_version rather than kernel version (uts.release) for * use in jails. This is equivalent to the value of uname -U. */ - snprintf(dest, sz, "%s:%d:%s", uts.sysname, __FreeBSD_version/100000, + error = asprintf(&abi, "%s:%d:%s", uts.sysname, __FreeBSD_version/100000, machine_arch); + if (error < 0) + return (NULL); - return (error); + return (abi); } static void @@ -453,10 +456,9 @@ config_init(const char *requested_repo) char *val; int i; const char *localbase; - char *env_list_item; + char *abi, *env_list_item; char confpath[MAXPATHLEN]; struct config_value *cv; - char abi[BUFSIZ]; for (i = 0; i < CONFIG_SIZE; i++) { val = getenv(c[i].key); @@ -512,7 +514,8 @@ config_init(const char *requested_repo) finalize: if (c[ABI].val == NULL && c[ABI].value == NULL) { - if (pkg_get_myabi(abi, BUFSIZ) != 0) + abi = pkg_get_myabi(); + if (abi == NULL) errx(EXIT_FAILURE, "Failed to determine the system " "ABI"); c[ABI].val = abi;