From nobody Fri Jan 05 00:23:08 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 4T5kgx5wX3z55fPT; Fri, 5 Jan 2024 00:23:09 +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 4T5kgx0MWKz4dsj; Fri, 5 Jan 2024 00:23:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704414189; 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=OkuyBEU5t9Zm7z/EdbN+I0kAxyEIs/bqOP3szrSNzw4=; b=ZBT6zP2Dhh6f35Pzd9rEt066aDRo+9GYtzHrfCGQeIzMt4nw9NA2BfvJ/to/bh3LjdQbav ofTCeQvjdmtrKs+OlcPCnKTK5f/0olpmJ7z1JffvoGYmWzrDB59AaAO3DJ1MHxeVGU7Ozi Ae2HbmVqreDmrwy8fUPchHGkgiJlkdfKm2UhgBxkufpSJDqmBkctAyXYD/Rc1axFTDhSIq ohW8JbfoFDiiwEhUvKI+WCDdmErH58YiLtPacx8pacxVYYs/skk4zj00m4IiAlHJRN73U0 UDt2MuS3twY+I7BXt8cp1NmtqbS9tYAU+55CtfzDkzBGDvDlidJuEuExo0yUEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704414189; 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=OkuyBEU5t9Zm7z/EdbN+I0kAxyEIs/bqOP3szrSNzw4=; b=ELwbU6qxmoCukpYedWG79KKu+r9kil7MuiGdyQUxe0v0TYiWpZZnLMYOw1kHZeHkYPaySr JXiWXpH9l4BdlW09uFad8Vd4zbfuU/aCiDdD7sF5ncsOrpIfduy/xDUiJerQaUoXUMXxuT tXVVEH1iQzw289xv6zooqNpaDiBe/Pr7IMrB81YmTrmsvcUITxsZHNo3QhgP3t1CsoDXRT DFOwLmlQ6egqymYvhC0E1g27vDc63I/F62cfeX5oP4OVVAnVSiMODQz7x3ZGQrzdVOZ95W GrWrDJEuf26/UKUG4YnJ5hZ3hGJ3cWb0wU1T2TpHyW7xIcdfw923Fu673mjgIQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704414189; a=rsa-sha256; cv=none; b=c/I7eq5jfkv1rC5k/W0Au/1zpOw6KMYNPQSnPCDwoBoHJmbk397Wn7NHh1PSwrXoMcR3ME 8PyvEzRRC4L16p8Afb5zYopiCjD+NGKFx0tA0nvf+2OWXAz4UNxJ2O/c23ZnSDKWygoqq9 2VpLojJonemYKOLWoNB5wQlCy29QWqk6aEy+Po2TS2A8kMDzO1tOo4Q9sBfvCp11IFQr4c yngsaGu/HUFjk6xZ7XLZT2Ho38fd+sx+GSrJ7BPez27Q8FYaKYkkutdmdieglyl+a4MYuv cQr44Clo29gTzZZ3nFw3i/VLO1DfTG0VxoEWtIrENYwHspikjPt8xWdJ0DoJjw== 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 4T5kgw6HLfzbpB; Fri, 5 Jan 2024 00:23:08 +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 4050N8No025414; Fri, 5 Jan 2024 00:23:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4050N8qH025411; Fri, 5 Jan 2024 00:23:08 GMT (envelope-from git) Date: Fri, 5 Jan 2024 00:23:08 GMT Message-Id: <202401050023.4050N8qH025411@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: 653e8fb20e84 - stable/13 - bsdinstall partedit: Replace malloc + sprintf with asprintf 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: 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/13 X-Git-Reftype: branch X-Git-Commit: 653e8fb20e8452de2c83c6f87dd3d0779f8eba3b Auto-Submitted: auto-generated The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=653e8fb20e8452de2c83c6f87dd3d0779f8eba3b commit 653e8fb20e8452de2c83c6f87dd3d0779f8eba3b Author: John Baldwin AuthorDate: 2023-10-16 23:25:15 +0000 Commit: John Baldwin CommitDate: 2024-01-05 00:08:25 +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 331cbc4ffba6..bc45a0f2d383 100644 --- a/usr.sbin/bsdinstall/partedit/gpart_ops.c +++ b/usr.sbin/bsdinstall/partedit/gpart_ops.c @@ -697,18 +697,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); } } } @@ -745,9 +743,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 ffc809507b08..0f116d2c716a 100644 --- a/usr.sbin/bsdinstall/partedit/partedit.c +++ b/usr.sbin/bsdinstall/partedit/partedit.c @@ -349,8 +349,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); items[i*2] = item; items[i*2 + 1] = "Pending"; i++;