From nobody Tue Jan 02 20:52:42 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 4T4Q623LJXz56HwQ; Tue, 2 Jan 2024 20:52:42 +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 4T4Q621kfCz4Xw5; Tue, 2 Jan 2024 20:52:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704228762; 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=P8lhF3+QkAYiaej47JlMGst5FRH9LsiGhGsU3vyTA6M=; b=lW5HX0ZbecZLEPEWtfc5xM2qx77g5TBEX4UihYRhyoEMtGKXhpl/0BQfcvdborWKtoDWdr 7Vuh49dYXQYrV/T+03jHQ7RYCmNCow0H1h1mPX+SQ49DhkBdlLvzzH8kkFGXckbv6hRrht KO4fScdZnoi1bIcSeWpltQIzWfYkiyAGB70aUc6e14S7ZHx1Y7ijK/0r3uba77VSAr+GEX l4cP18bqA/NRqbBJ2iEsL7epSZBbsGBIWSjrVicS+EN71tbrtI+7szRguxCHsFNXk6EBhJ INqqq5G4gYnjQl0jOiMcRJhkRJFnHeMGBSYg8NQItZHSP5VUUgRdupfErKdq4g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704228762; a=rsa-sha256; cv=none; b=WAZVbRDYxgdAoHReNSy9+KxujRqyskdrIwrmhpv9WNpVRzLZSORIKXy2ALaCMJr5nHGJD7 9huudvZESZkvQjshON1FDQpYM8Zo2rA0ID7lzhcH3fu9xqDDz2x4LDdfWr3irTvZqhOU7W TrmR7xn2F9eco7P9DE3eRZEoq68pIwM/Trv65ue99fyi0YOI8RDr6mKZEQef+wYiJR2XSk uWEaUOc41cr9H82T/AQ7pYzVRMCl04Flf4vLoQw82kEfm+EMdtfwrh3R9ghthJK0JtZkbd hHGRm0804LJA8VIGdAqCaTl+LWcw+bXg/llTvXdhLBFBbgcc3oN3p2KhnVlHfQ== 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=1704228762; 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=P8lhF3+QkAYiaej47JlMGst5FRH9LsiGhGsU3vyTA6M=; b=XXJ4AibQXERgd5E+OdD0+/yo/gMtGV6KoADJZxHlbjWcwF9wuTqomdKcUEq3KurXBUMz5x Su1GHfaA2p+u5QAIH+pq97R/S/aA8AOkPlE/X2FEe8+w7aTuGGrhIUUVBF3mWVCQDRFwG3 fqiOANYdmDjmRKndjF8oXyL6YDWKD5CxG5yjMFLSB0ASAW/DapT7r5AMuzVpQCR1KN9zem GmTsR+V8Xc5pAp9ELY5J68DGCoTLy1OSnZRa+SH5zBlYGaxxGjHOE4nHLX7nIm9Ut7XIbC 9RrOlBAjl+cDtRKd5qSspee39RAaHdIZnd+mWBsliKNC1UglY1skCO71yJomwg== 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 4T4Q620mhKz1G1V; Tue, 2 Jan 2024 20:52:42 +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 402KqgD1037153; Tue, 2 Jan 2024 20:52:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 402KqgIT037150; Tue, 2 Jan 2024 20:52:42 GMT (envelope-from git) Date: Tue, 2 Jan 2024 20:52:42 GMT Message-Id: <202401022052.402KqgIT037150@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: 8ff950573c10 - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: 8ff950573c104d99f4183b27801258566afe546c Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=8ff950573c104d99f4183b27801258566afe546c commit 8ff950573c104d99f4183b27801258566afe546c Author: John Baldwin AuthorDate: 2023-10-16 23:25:38 +0000 Commit: John Baldwin CommitDate: 2024-01-02 19:20:37 +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 64a45deb9f8a..5c4ec5706c1c 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"; @@ -658,7 +664,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; @@ -1181,7 +1189,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; @@ -1233,7 +1242,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; @@ -1248,7 +1259,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 ba10350029a9..ba01e115bcf4 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 9e25a2b31d1f..d1ffd09c0d5e 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);