From nobody Mon Oct 16 23:32:21 2023 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 4S8YLG1PVLz4whgc; Mon, 16 Oct 2023 23:32:22 +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 4S8YLG0rdWz3FqG; Mon, 16 Oct 2023 23:32:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697499142; 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=IxwwtkzgYnJax6oE1fLo88ZQEAgJaavBNcT/rtLSOaM=; b=DiA1zNJBGM33g45PICB43HGOyoXOMiI5VQSiomrdRycxRNze2RLQk9REvteld2aWADCNO8 MRrRQEdOvxetXZWM2O3gFu2TVhX+HIcuDAzAcKxsBBwza57QxIAHapqVyvRqsks1/3wrgV w+f07q1TdKXcFP5fY3undRcKfWzjqdirlW48JkiDKmz/j0HOnkkD0Fzvf9e89zkqhcPhe1 QARPnyiYOf35S+wHxirWhtx6/zuvN8bF8K+GUN4di40IlBNaQb+Whb/yVKY+P9Xyj40GIc JYx/dbogc2nCta51n36oGa5qxRywKVs4W8NwiZFzGUoOb6M+BvzKLReVss4NLw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697499142; a=rsa-sha256; cv=none; b=GdFrgdwYJ6erQSYVbWQp+x5xJkhIHQvGDi9o2pfAdawDgDZ2z7IHLAOxRlrHsI3h5TBMND /s0l8So91fkTPx9GwesPSLvsbwBGM3qU753Vqnn6V6Tt/mMZhF2G9+WgultmofAVTJ0L72 XiVOk4LNFJOFRCN1w4Wx2IWBG6m+LirhWo0JJghurMNPllcEPSLtmXrA/DGZtK3X3IATN2 qAgU1D63V9k70jpJYvyOeF4194U/arDiO9aNqI5p8z5lidmnnahYRbAwtkcL1fPWN0+Iyl QXqjKfuP+o933rphe2pQAPJfbRw5Wu+IMyvhLFnCt5FzKNLBWmS79nyaj9g6xw== 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=1697499142; 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=IxwwtkzgYnJax6oE1fLo88ZQEAgJaavBNcT/rtLSOaM=; b=acFlu6ts3G9aog6EhNcdi+30yZsR+Xxtvmx5UJUBl/eCC1fPV+CggQ3djE0aj1u1mdKXZh wMsMeaeAuWoyrDBFSdghpETDgTLaYGWKcIH2hXtDroQ74/rLIKxkefcSMei2Mn58KtFabP T6Yz5yObddBCq2SknD6TGR3oCoCSCeoBbwCH3JvCngUOTImwSZMb7tx0FG88kpDPxBQsBT eATWUlL/rGpF8ikAS2BFwNIStd+TdwoMXo+2wukyQdnW5zAOwzEShOuonrGSEoTlaQ+GwK +wMFS5DnnRool03LapN4TDkt1VOYpjFuUid//JAsRrZhVE881OWrhRY4K5nQRQ== 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 4S8YLF6xNzz114P; Mon, 16 Oct 2023 23:32:21 +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 39GNWLCQ094820; Mon, 16 Oct 2023 23:32:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39GNWLX6094817; Mon, 16 Oct 2023 23:32:21 GMT (envelope-from git) Date: Mon, 16 Oct 2023 23:32:21 GMT Message-Id: <202310162332.39GNWLX6094817@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: 6e8bf24073a1 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 6e8bf24073a1867c4b21bd84438a8b01ce91d82d Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=6e8bf24073a1867c4b21bd84438a8b01ce91d82d commit 6e8bf24073a1867c4b21bd84438a8b01ce91d82d Author: John Baldwin AuthorDate: 2023-10-16 23:25:38 +0000 Commit: John Baldwin CommitDate: 2023-10-16 23:25:38 +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 --- 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 7395030b26aa..0bcd17950daf 100644 --- a/usr.sbin/bsdinstall/partedit/gpart_ops.c +++ b/usr.sbin/bsdinstall/partedit/gpart_ops.c @@ -62,12 +62,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); } bsddialog_initconf(&conf); @@ -263,7 +264,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); conf.button.default_cancel = true; @@ -298,7 +301,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); conf.button.default_cancel = true; @@ -484,10 +489,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); bsddialog_initconf(&conf); conf.title = "Error"; @@ -659,7 +665,9 @@ editpart: if (strcmp(items[2].value, "/") == 0 && !is_fs_bootable(scheme, items[0].value)) { 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].value); conf.button.default_cancel = true; @@ -1182,7 +1190,8 @@ addpartform: if (expand_number(items[1].value, &bytes) != 0) { char error[512]; - sprintf(error, "Invalid size: %s\n", strerror(errno)); + snprintf(error, sizeof(error), "Invalid size: %s\n", + strerror(errno)); conf.title = "Error"; bsddialog_msgbox(&conf, error, 0, 0); goto addpartform; @@ -1234,7 +1243,9 @@ addpartform: /* If this is the root partition, check that this scheme is bootable */ if (strcmp(items[2].value, "/") == 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); conf.button.default_cancel = true; @@ -1249,7 +1260,9 @@ addpartform: if (strcmp(items[2].value, "/") == 0 && !is_fs_bootable(scheme, items[0].value)) { 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].value); conf.button.default_cancel = true; diff --git a/usr.sbin/bsdinstall/partedit/part_wizard.c b/usr.sbin/bsdinstall/partedit/part_wizard.c index 5618d5ffe025..a3c5cb43ec51 100644 --- a/usr.sbin/bsdinstall/partedit/part_wizard.c +++ b/usr.sbin/bsdinstall/partedit/part_wizard.c @@ -277,7 +277,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 " OSNAME ", it must be repartitioned. This will destroy all " "data on the disk. Are you sure you want to proceed?", @@ -367,7 +368,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 " OSNAME " (%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 6a216f31161b..74606a2ef8f3 100644 --- a/usr.sbin/bsdinstall/partedit/partedit.c +++ b/usr.sbin/bsdinstall/partedit/partedit.c @@ -436,7 +436,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)); conf.title = "Error"; bsddialog_msgbox(&conf, message, 0, 0);