git: 10415f634193 - stable/14 - bsdinstall partedit: Use asprintf to build wrapper command for newfs
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 02 Jan 2024 20:52:40 UTC
The branch stable/14 has been updated by jhb:
URL: https://cgit.FreeBSD.org/src/commit/?id=10415f6341936216197c9bb127e2b579a2189a33
commit 10415f6341936216197c9bb127e2b579a2189a33
Author: John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2023-10-16 23:25:25 +0000
Commit: John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-01-02 19:20:37 +0000
bsdinstall partedit: Use asprintf to build wrapper command for newfs
Don't abuse the message[] static buffer used elsewhere for error
messages to generate the command that actually newfs's each
filesystem. Use asprintf to a more aptly-named 'char *command'
variable to construct the string instead. This avoids potential bugs
from truncation of the command string.
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D42239
(cherry picked from commit a8676bf367b099dcc97ff61031cbf4ceb5e37899)
---
usr.sbin/bsdinstall/partedit/partedit.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/usr.sbin/bsdinstall/partedit/partedit.c b/usr.sbin/bsdinstall/partedit/partedit.c
index 3067efc0ae9b..9e25a2b31d1f 100644
--- a/usr.sbin/bsdinstall/partedit/partedit.c
+++ b/usr.sbin/bsdinstall/partedit/partedit.c
@@ -345,6 +345,7 @@ apply_changes(struct gmesh *mesh)
const char **minilabel;
const char *fstab_path;
FILE *fstab;
+ char *command;
struct bsddialog_conf conf;
nitems = 1; /* Partition table changes */
@@ -387,10 +388,11 @@ apply_changes(struct gmesh *mesh)
bsddialog_mixedgauge(&conf,
"Initializing file systems. Please wait.", 0, 0,
i * 100 / nitems, nitems, minilabel, miniperc);
- sprintf(message, "(echo %s; %s) >>%s 2>>%s",
+ asprintf(&command, "(echo %s; %s) >>%s 2>>%s",
md->newfs, md->newfs, getenv("BSDINSTALL_LOG"),
getenv("BSDINSTALL_LOG"));
- error = system(message);
+ error = system(command);
+ free(command);
miniperc[i] = (error == 0) ?
BSDDIALOG_MG_COMPLETED : BSDDIALOG_MG_FAILED;
i++;