From nobody Mon Oct 16 23:32:19 2023 X-Original-To: dev-commits-src-main@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 4S8YLD0hY1z4whgV; Mon, 16 Oct 2023 23:32:20 +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 4S8YLC6mf1z3Fry; Mon, 16 Oct 2023 23:32:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697499140; 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=0IHlS5k76PpDKsHgmJpX567709ZRC3fNEthkwou15m4=; b=nR87H99Kz1uZxCeH4jSugIQnYfEyviYYbmogtEj/IrePgeOAobVSCjiQ9fegdH6oBQ1io1 EAOMHNh27XunktWUUF3w/Dai5PS9s/dI6aWaT701t2z1ZKJdNn03EtcgZAB0rW09DmmpsG cBJtlbnBXtJzGL+5vYlnwSSYqccS3W9AhuLioXISZ7N6Rvg4G2w5aa1DmiiGcC/GsEH8FP MhPY+8aJYwDuWm0n941BL/nNlHr2tou+MVQHcrcEm6Re1h5bZ7ChzxGyQG5sF+mEQzPPtk +1jlALXslik6Zr/pD92mxkY4z4cG0gCB0yJbveYoV1Iqa9Tk8RxJIHOrIt/gNQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697499140; a=rsa-sha256; cv=none; b=A8uE9KPQ20NHJpl+QIOJJ+PT77bI8IBMloLLLLSkUDjvOe3VNYSVkSiSUJrPvh4jr2kHDV ReY8c8pxyoie42lIc9S9St/yQYiyHU6vAlz3sU6miex2pALdF/svmarKKM1VpaQzKAbx05 gyv4cUP1ql0r9J5mDwn0bFNWXdBt2KlMMCOWKIoqS6lsmUIMuTDKKiCXvRazK795MSvRqO dKg5LZW157YucbQpzR4QzrkPtZ2Qhz7K1WMd/VWl38e1SWHtjs7TIHowYgBqpeGiV8UNxW mGXUkee5jg45RnCZ3of0tKC6VVxb3+6qGyw+aDTwDK6V5W5UFUIVNh4xRX0dgg== 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=1697499140; 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=0IHlS5k76PpDKsHgmJpX567709ZRC3fNEthkwou15m4=; b=kml6q2pYul8W7rgvrq+sSvAR1GRFz8BqprpCsCtlCf2kbIRRUwFTMnBpHoa6xY4I7M/tRs y8Hxk41Iyb3+npxeL+iekJft/d188+TWHGJvXnRAl033vXC/PPmrMAGuAOSCb8hyW7284f l6waM4g2+8Q9GKhU3cRO8Y1l31KjSVcK8Cb5QczMOXiFVPgW/anhD4Gcwwbntk+tk4O60F 0M/u09oPbiw1iNE9MLIZY07XXRCcZPfOqLvZxJljLC5y9P5yfjxbgY9J2V4xpbmQKMivrU m9ovX/UbE6++MY3REp7JfZxKAC6yB6Gl3JKOj8mfOxfXi3+tQAFezSwqGHesSg== 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 4S8YLC5Xwbz118T; Mon, 16 Oct 2023 23:32:19 +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 39GNWJcb094699; Mon, 16 Oct 2023 23:32:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39GNWJEO094696; Mon, 16 Oct 2023 23:32:19 GMT (envelope-from git) Date: Mon, 16 Oct 2023 23:32:19 GMT Message-Id: <202310162332.39GNWJEO094696@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 51749e05e96e - main - bsdinstall partedit: Replace malloc + sprintf with asprintf List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 51749e05e96eb07134a38984a8c06608b20f07ea Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=51749e05e96eb07134a38984a8c06608b20f07ea commit 51749e05e96eb07134a38984a8c06608b20f07ea Author: John Baldwin AuthorDate: 2023-10-16 23:25:15 +0000 Commit: John Baldwin CommitDate: 2023-10-16 23:25:15 +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 --- 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 7f34819a3d4d..7395030b26aa 100644 --- a/usr.sbin/bsdinstall/partedit/gpart_ops.c +++ b/usr.sbin/bsdinstall/partedit/gpart_ops.c @@ -732,18 +732,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); } } } @@ -780,9 +778,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 bb2580789fe8..b6c81ad9fc25 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++;