From nobody Fri Jan 05 00:23:11 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 4T5kgz4ZpZz55fJ9; Fri, 5 Jan 2024 00:23:11 +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 4T5kgz2cpLz4dw9; Fri, 5 Jan 2024 00:23:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704414191; 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=o7MwXsdTheipnxBHKBfB+chs0oxN4VySubizqV5hHFE=; b=P6JIxsrDHAnZ4if1WGUUEMhIdtCTHj6huYjfpCpyjWUyA9o/sN5Q0FI6U216m+FTgax3Uc ak/QyNyOYAoWpCtVcD3RymjwK2iHcSoFp1kLoyieS1530e08Fsf2NzFDIcnKsV1QCYsOqL i8ed8aCTpf3fe14wkl+6v74aGiPE9k1RIivNSTQZTz/4zT0FBI6Z9/GNDH/YCpZnwn6fzU x84dUnRzosAKxkheyvk5CHst4JDjTs4lJ52SPXWTg+rVDASpbmIwLPYhNHSf+eVJQK21h7 SBDW6ExMA0no4RseCFRX7/nBMQqgGEgjqf2ISF3CHORZXkJN90bStIheV9HPhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704414191; 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=o7MwXsdTheipnxBHKBfB+chs0oxN4VySubizqV5hHFE=; b=mieH1Wsw4xzDPPdsffIQBlqaiF1J8dWSUetzAYLW8BiXsYJcYSq31kMnojx47q4OlTBhMz 8T5BrnEzkO0QTXV67+85bHS6FsoZifxVEzQN/aIunEYu0QR8G9GzKEPL875+z64dUaeSen D8RoxdZneEqEo7rLVgVfzDu3oup3NKtzO4/wrWOBxPXye/MiCUEkAXZnK13Ud2E4LekYpF jdDFEoWoTcdbrUCqVr36295HDuaaGBS1mxv8wd6O/2N3T42WnWvBnEIyAONfKn9kPaY+rm GIq46jKXXmSKQO/zcxhiPcphtN4DBRVrA11gP7mw7xT2BkN9vNP0NR35bcR4Kw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704414191; a=rsa-sha256; cv=none; b=vvC7vifo6oP/W5vL1fTU9j5JG4mhBvHnjUaqZ3dW91d/M8zWn/0hQ0ozuVt1ScuyheyGVE htk4O1coCF/2tJ5G6J4LJEA4Soah2B/ClouZC2MirhlLO/6bn3BK5OUD9EL2Q8TJS0DHS+ b+uyM+pV6W47IWar4GHA8EuiRRO4hMgg2qPQi3PeqORcL6n46GWcej8f/a3o6znhlvfMIc LD7djHnpuWSzsYo4TaPeww86wVZeoSas3dWRPnG7UJz7ipcXCTYCqDzfsD2UPCbk/LOqdO CFS6ID1EucRNXnMmdLq0gRf1ueE43IAw0A2aYTboxIKflzezO6+AT/v9xahR4A== 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 4T5kgz1YdjzbpC; Fri, 5 Jan 2024 00:23:11 +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 4050NBAX025533; Fri, 5 Jan 2024 00:23:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4050NBJB025530; Fri, 5 Jan 2024 00:23:11 GMT (envelope-from git) Date: Fri, 5 Jan 2024 00:23:11 GMT Message-Id: <202401050023.4050NBJB025530@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: 91a736d7016f - stable/13 - bsdinstall partedit: Use snprintf instead of sprintf for error messages 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: 91a736d7016f26b2ec2e64553c2183555cc077d1 Auto-Submitted: auto-generated The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=91a736d7016f26b2ec2e64553c2183555cc077d1 commit 91a736d7016f26b2ec2e64553c2183555cc077d1 Author: John Baldwin AuthorDate: 2023-10-16 23:25:38 +0000 Commit: John Baldwin CommitDate: 2024-01-05 00:16:24 +0000 bsdinstall partedit: Use snprintf instead of sprintf for error messages When generating a message for a dialog box into a static buffer, use snprintf instead of sprintf to avoid buffer overflows. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D42240 (cherry picked from commit 6e8bf24073a1867c4b21bd84438a8b01ce91d82d) --- usr.sbin/bsdinstall/partedit/gpart_ops.c | 37 ++++++++++++++++++++---------- usr.sbin/bsdinstall/partedit/part_wizard.c | 6 +++-- usr.sbin/bsdinstall/partedit/partedit.c | 3 ++- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/usr.sbin/bsdinstall/partedit/gpart_ops.c b/usr.sbin/bsdinstall/partedit/gpart_ops.c index bc45a0f2d383..7ab5e16c063b 100644 --- a/usr.sbin/bsdinstall/partedit/gpart_ops.c +++ b/usr.sbin/bsdinstall/partedit/gpart_ops.c @@ -56,12 +56,13 @@ gpart_show_error(const char *title, const char *explanation, const char *errstr) while (errmsg[0] == ' ') errmsg++; if (errmsg[0] != '\0') - sprintf(message, "%s%s. %s", explanation, - strerror(error), errmsg); + snprintf(message, sizeof(message), "%s%s. %s", + explanation, strerror(error), errmsg); else - sprintf(message, "%s%s", explanation, strerror(error)); + snprintf(message, sizeof(message), "%s%s", explanation, + strerror(error)); } else { - sprintf(message, "%s%s", explanation, errmsg); + snprintf(message, sizeof(message), "%s%s", explanation, errmsg); } dialog_msgbox(title, message, 0, 0, TRUE); @@ -245,7 +246,9 @@ parttypemenu: if (!is_scheme_bootable(items[choice].name)) { char message[512]; - sprintf(message, "This partition scheme (%s) is not " + + snprintf(message, sizeof(message), + "This partition scheme (%s) is not " "bootable on this platform. Are you sure you want " "to proceed?", items[choice].name); dialog_vars.defaultno = TRUE; @@ -276,7 +279,9 @@ schememenu: if (!is_scheme_bootable(scheme)) { char message[512]; - sprintf(message, "This partition scheme (%s) is not " + + snprintf(message, sizeof(message), + "This partition scheme (%s) is not " "bootable on this platform. Are you sure you want " "to proceed?", scheme); dialog_vars.defaultno = TRUE; @@ -458,10 +463,11 @@ gpart_partcode(struct gprovider *pp, const char *fstype) } /* Shell out to gpart for partcode for now */ - sprintf(command, "gpart bootcode -p %s -i %s %s", + snprintf(command, sizeof(command), "gpart bootcode -p %s -i %s %s", partcode_path(scheme, fstype), indexstr, pp->lg_geom->lg_name); if (system(command) != 0) { - sprintf(message, "Error installing partcode on partition %s", + snprintf(message, sizeof(message), + "Error installing partcode on partition %s", pp->lg_name); dialog_msgbox("Error", message, 0, 0, TRUE); } @@ -626,7 +632,9 @@ editpart: if (strcmp(items[2].text, "/") == 0 && !is_fs_bootable(scheme, items[0].text)) { char message[512]; - sprintf(message, "This file system (%s) is not bootable " + + snprintf(message, sizeof(message), + "This file system (%s) is not bootable " "on this system. Are you sure you want to proceed?", items[0].text); dialog_vars.defaultno = TRUE; @@ -1122,7 +1130,8 @@ addpartform: if (expand_number(items[1].text, &bytes) != 0) { char error[512]; - sprintf(error, "Invalid size: %s\n", strerror(errno)); + snprintf(error, sizeof(error), "Invalid size: %s\n", + strerror(errno)); dialog_msgbox("Error", error, 0, 0, TRUE); goto addpartform; } @@ -1170,7 +1179,9 @@ addpartform: /* If this is the root partition, check that this scheme is bootable */ if (strcmp(items[2].text, "/") == 0 && !is_scheme_bootable(scheme)) { char message[512]; - sprintf(message, "This partition scheme (%s) is not bootable " + + snprintf(message, sizeof(message), + "This partition scheme (%s) is not bootable " "on this platform. Are you sure you want to proceed?", scheme); dialog_vars.defaultno = TRUE; @@ -1184,7 +1195,9 @@ addpartform: if (strcmp(items[2].text, "/") == 0 && !is_fs_bootable(scheme, items[0].text)) { char message[512]; - sprintf(message, "This file system (%s) is not bootable " + + snprintf(message, sizeof(message), + "This file system (%s) is not bootable " "on this system. Are you sure you want to proceed?", items[0].text); dialog_vars.defaultno = TRUE; diff --git a/usr.sbin/bsdinstall/partedit/part_wizard.c b/usr.sbin/bsdinstall/partedit/part_wizard.c index db689fd223d7..90dba58383e2 100644 --- a/usr.sbin/bsdinstall/partedit/part_wizard.c +++ b/usr.sbin/bsdinstall/partedit/part_wizard.c @@ -251,7 +251,8 @@ query: char warning[512]; int subchoice; - sprintf(warning, "The existing partition scheme on this " + snprintf(warning, sizeof(warning), + "The existing partition scheme on this " "disk (%s) is not bootable on this platform. To install " "FreeBSD, it must be repartitioned. This will destroy all " "data on the disk. Are you sure you want to proceed?", @@ -338,7 +339,8 @@ wizard_makeparts(struct gmesh *mesh, const char *disk, const char *fstype, HN_DECIMAL); humanize_number(neededstr, 7, MIN_FREE_SPACE, "B", HN_AUTOSCALE, HN_DECIMAL); - sprintf(message, "There is not enough free space on %s to " + snprintf(message, sizeof(message), + "There is not enough free space on %s to " "install FreeBSD (%s free, %s required). Would you like " "to choose another disk or to open the partition editor?", disk, availablestr, neededstr); diff --git a/usr.sbin/bsdinstall/partedit/partedit.c b/usr.sbin/bsdinstall/partedit/partedit.c index c8961d03c5cc..599d2b2ec234 100644 --- a/usr.sbin/bsdinstall/partedit/partedit.c +++ b/usr.sbin/bsdinstall/partedit/partedit.c @@ -421,7 +421,8 @@ apply_changes(struct gmesh *mesh) fstab_path = "/etc/fstab"; fstab = fopen(fstab_path, "w+"); if (fstab == NULL) { - sprintf(message, "Cannot open fstab file %s for writing (%s)\n", + snprintf(message, sizeof(message), + "Cannot open fstab file %s for writing (%s)\n", getenv("PATH_FSTAB"), strerror(errno)); dialog_msgbox("Error", message, 0, 0, TRUE); return (-1);