From nobody Tue Jan 2 20:52:39 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 4T4Q6025xvz56J1Q; Tue, 2 Jan 2024 20:52:40 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4T4Q600Dp3z4XsR; Tue, 2 Jan 2024 20:52:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704228760; 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=uw9fM/wNGpk041/hnWsm386jLo1ybRvERleIzLnq/tU=; b=Jd407KH3Pyy5MCuNz2E94018OglcKyex0TCmYnIvqdJYmmr24+NsGkCgimaPKMUJInY3kL SlZVXy+Krc5HL7U7T2B1kV94nCESxmk/9ZwNRJ3U6nkGY2CXMCeYVT1NXn2kbNmllpFsGw zi4UPh3dcVrwzmm7xTbutvxo83m71+RElhV1J5DT1O4xnofl/kzaCwfkZ+7ncJ51BY4xv1 Rl8rEd8NgA96WUSTuz14EnJOhU4+aOzdOUBSSRIxYwq188FR0O7XXAiCyaKfiRb9bB3505 esTddIHTu0KWOyVqOLJYBL5OX+rlZ5xxkzhAT6oE/ysKciTKUNcC8Q6r82FxQA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704228760; a=rsa-sha256; cv=none; b=bZhLCkSO79O9V5dnJMPF+rh725bosldjmIc8jOIcTnudJ5Zmp8CiiDsHA6mi6VSeSVlad1 tHw+0AHEBInyH+M6SNGMbbnnxDXeL0Yrvo/HnHd+iMqqUcJGdL99SLC8DYPUVZibjEgbWT biT8LTE5ln/q0F7hSmkngcj0mGsJbMhM/CS7AqljEc2nUUQBs46RGmhOjaSnuB7z4P8VmW YjO4XBefaJkBIxO0lzT7GXdmY/Vjp4VppwRPctQJsISsRAW4e0kmbUBr0YJnzNCMMYdtFv ZmOMifg8pmJC2BKeIaIMhb+zXE2FLMQuWElYodxD4h+2tJ87D8P28rIq7kYsQQ== 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=1704228760; 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=uw9fM/wNGpk041/hnWsm386jLo1ybRvERleIzLnq/tU=; b=VQ7Q6/AcH/+SDOeL9LOA9ZHpGLijXOUrOR204xEh40cMLEfxiy666YSkuvddZeo0EWMLSZ NeGbpaiy87xZxQR/2FTYBOP/6UAMyGdu9nm6Jc84EfqxQ4cec81bVT32gCbtL8Ev6a9q99 lPJSu9vkr/PZV2GeHr/VTLMhEyDgEjX8JagKvC0DVjJoZe+iqMaeWqRCP2trNyQS1xs8oI enXnRVnxMTi5F4MbWkTdZAmj04ErAMkw2FcXBeOhrz78x5u/229UcutyHBfBsNgnb46k7Z M5nQUHfGGYKmsZVVw9Rrj+++XIHtLmFEDOkU/Uf9JJMhdKxS6Rb25EYKOCsiFA== 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 4T4Q5z69mLz1FXg; Tue, 2 Jan 2024 20:52:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 402KqdTa037036; Tue, 2 Jan 2024 20:52:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 402KqdwD037033; Tue, 2 Jan 2024 20:52:39 GMT (envelope-from git) Date: Tue, 2 Jan 2024 20:52:39 GMT Message-Id: <202401022052.402KqdwD037033@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin <jhb@FreeBSD.org> Subject: git: bb049096be78 - stable/14 - bsdinstall partedit: Replace malloc + sprintf with asprintf List-Id: Commit messages for all branches of the src repository <dev-commits-src-all.freebsd.org> List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: <mailto:dev-commits-src-all+help@freebsd.org> List-Post: <mailto:dev-commits-src-all@freebsd.org> List-Subscribe: <mailto:dev-commits-src-all+subscribe@freebsd.org> List-Unsubscribe: <mailto:dev-commits-src-all+unsubscribe@freebsd.org> Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: 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/14 X-Git-Reftype: branch X-Git-Commit: bb049096be7846625ce7159470153e0bae893b6d Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=bb049096be7846625ce7159470153e0bae893b6d commit bb049096be7846625ce7159470153e0bae893b6d Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2023-10-16 23:25:15 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2024-01-02 19:20:37 +0000 bsdinstall partedit: Replace malloc + sprintf with asprintf This avoids potential bugs with the length passed to malloc not matching the string written via sprintf. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D42238 (cherry picked from commit 51749e05e96eb07134a38984a8c06608b20f07ea) --- usr.sbin/bsdinstall/partedit/gpart_ops.c | 10 +++------- usr.sbin/bsdinstall/partedit/partedit.c | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/usr.sbin/bsdinstall/partedit/gpart_ops.c b/usr.sbin/bsdinstall/partedit/gpart_ops.c index 65f53f31545f..64a45deb9f8a 100644 --- a/usr.sbin/bsdinstall/partedit/gpart_ops.c +++ b/usr.sbin/bsdinstall/partedit/gpart_ops.c @@ -731,18 +731,16 @@ set_default_part_metadata(const char *name, const char *scheme, } if (newfs != NULL && newfs[0] != '\0') { - md->newfs = malloc(strlen(newfs) + strlen(" /dev/") + - strlen(mountpoint) + 5 + strlen(name) + 1); if (strcmp("freebsd-zfs", type) == 0) { zpool_name = strdup((strlen(mountpoint) == 1) ? "root" : &mountpoint[1]); for (i = 0; zpool_name[i] != 0; i++) if (!isalnum(zpool_name[i])) zpool_name[i] = '_'; - sprintf(md->newfs, "%s %s /dev/%s", newfs, + asprintf(&md->newfs, "%s %s /dev/%s", newfs, zpool_name, name); } else { - sprintf(md->newfs, "%s /dev/%s", newfs, name); + asprintf(&md->newfs, "%s /dev/%s", newfs, name); } } } @@ -779,9 +777,7 @@ set_default_part_metadata(const char *name, const char *scheme, if (strcmp("freebsd-zfs", type) == 0) { md->fstab->fs_spec = strdup(zpool_name); } else { - md->fstab->fs_spec = malloc(strlen(name) + - strlen("/dev/") + 1); - sprintf(md->fstab->fs_spec, "/dev/%s", name); + asprintf(&md->fstab->fs_spec, "/dev/%s", name); } md->fstab->fs_file = strdup(mountpoint); /* Get VFS from text after freebsd-, if possible */ diff --git a/usr.sbin/bsdinstall/partedit/partedit.c b/usr.sbin/bsdinstall/partedit/partedit.c index 3c5f552a935c..3067efc0ae9b 100644 --- a/usr.sbin/bsdinstall/partedit/partedit.c +++ b/usr.sbin/bsdinstall/partedit/partedit.c @@ -360,8 +360,8 @@ apply_changes(struct gmesh *mesh) TAILQ_FOREACH(md, &part_metadata, metadata) { if (md->newfs != NULL) { char *item; - item = malloc(255); - sprintf(item, "Initializing %s", md->name); + + asprintf(&item, "Initializing %s", md->name); minilabel[i] = item; miniperc[i] = BSDDIALOG_MG_PENDING; i++;