From nobody Tue Jun 27 17:19:42 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 4QrBKW0lRtz4f4LJ; Tue, 27 Jun 2023 17:19:43 +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 4QrBKV5nhtz3NMq; Tue, 27 Jun 2023 17:19:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687886382; 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=BFl7OEyshRRfQA1hYwq9Iog09GWhjz/qRPqGdSx2OA4=; b=nLzxYj7XDSe4RqWRa+y/6Ur+sOvnLdZIO1o7cvSW2JZf/39KCa5MevduV5MriyR+GIgyFv YPI3oOR/Yd12Bmwsed70h4n9r/6zpMUjbmJfolnnf9WKn1Xh1o0Fcw0d5lF6z2RcXjPWV6 20xgkAFiK2vKDT1Gw26lt9Wv7yTEjh6sQszioatfjBsIMby5w/hfsfSi+OBUm4kIcRvdbK p7eaeJAjNoptHYsC5q3Jjup4i0wxJSBMoThtotbJaijkRxLHmTGAqsp8NQuaAQS1Ly6Amt /1yRsV7DuabJobLQ1QlgJO6R+RMoMUuKTXPEsQyEuZBQCMtS9JALPwP/hA2AAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687886382; 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=BFl7OEyshRRfQA1hYwq9Iog09GWhjz/qRPqGdSx2OA4=; b=nIocFhyF6BT0LEetdqQ7gQRjrBFcBxYL8yE+aubI1VSwWlPLa5wQxr5QNhGdhOXR2ll1uG RKaM085onBr748UhkgW28nxmaaa1k5QybBuSMR1CL2nz9dlAhemqzKsN/Cq8ICf64iNh2X 5T4oqEQZx9cyPSPCTGgYtx/MD0mOAAZ7UJ2nhD9FStR7QWKhJ9eEid2USWVW39ehiVToSg oh+HR1HigmzBZrP8rtbu0vGAgXFvxYGVCallx9iPH0xkuh8qiK50vCkhbNjsX7IVYdBBHq lC0gEkd0gvn6fAu+D+9RYRwxx7zD0Z+0RZ7xcY9tOG+/MTa0FTH1AFA+tlNqAg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1687886382; a=rsa-sha256; cv=none; b=jKoiO2z0dlq0smOCQYk+3TYGP36WiVxSRenDVxuqp3/CndEkgPR+tMvXGLeW0H8MdbyKYf thtApL5meBbQSlNIJIXt+cZPo/rp0+hUNCE8U6az/D7NUsGx+qjNKCkFeNuDZmZXVpTaSJ dc7b0WiqnE2TRGu3gUgxSSfWqI7cjvwlQhPTftIk0bdQEO1Nn3DCz4+rs2X687al6HyL2n 2rQXUhGTrySTi+qyxaPLEOutO5WM08Fs9m8QYNnXe2hnWdcihlnp4oHbYZmj/9GRL2/LAw ZgZCFtcXruC1t3b3gmxt7oI7eOgU/JrjbB351HHREMjJzAAZkxU59JCZzGr2ZA== 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 4QrBKV2fdpz1148; Tue, 27 Jun 2023 17:19:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 35RHJglY006851; Tue, 27 Jun 2023 17:19:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35RHJgPH006850; Tue, 27 Jun 2023 17:19:42 GMT (envelope-from git) Date: Tue, 27 Jun 2023 17:19:42 GMT Message-Id: <202306271719.35RHJgPH006850@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: f66a8328c3ef - main - bsdinstall: Replace correct, but fragile, string builder with open_memstream. 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: f66a8328c3effcb4fbd7807b798d0288b865421d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=f66a8328c3effcb4fbd7807b798d0288b865421d commit f66a8328c3effcb4fbd7807b798d0288b865421d Author: John Baldwin AuthorDate: 2023-06-27 17:19:32 +0000 Commit: John Baldwin CommitDate: 2023-06-27 17:19:32 +0000 bsdinstall: Replace correct, but fragile, string builder with open_memstream. The old one triggered a false positive -Warray-bounds from GCC (the compiler assumed len was always 0), but it was also fragile with manually computed lengths paired with strcat vs using a string builder. Differential Revision: https://reviews.freebsd.org/D40658 --- usr.sbin/bsdinstall/partedit/scripted.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/usr.sbin/bsdinstall/partedit/scripted.c b/usr.sbin/bsdinstall/partedit/scripted.c index 48ac94d112f2..62c36724d7c5 100644 --- a/usr.sbin/bsdinstall/partedit/scripted.c +++ b/usr.sbin/bsdinstall/partedit/scripted.c @@ -195,23 +195,26 @@ int parse_disk_config(char *input) int scripted_editor(int argc, const char **argv) { - char *token; - int i, error = 0, len = 0; + FILE *fp; + char *input, *token; + size_t len; + int i, error = 0; - for (i = 1; i < argc; i++) - len += strlen(argv[i]) + 1; - char inputbuf[len], *input = inputbuf; - strcpy(input, argv[1]); + fp = open_memstream(&input, &len); + fputs(argv[1], fp); for (i = 2; i < argc; i++) { - strcat(input, " "); - strcat(input, argv[i]); + fprintf(fp, " %s", argv[i]); } + fclose(fp); while ((token = strsep(&input, ";")) != NULL) { error = parse_disk_config(token); - if (error != 0) + if (error != 0) { + free(input); return (error); + } } + free(input); return (0); }