git: a8676bf367b0 - main - bsdinstall partedit: Use asprintf to build wrapper command for newfs
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 16 Oct 2023 23:32:20 UTC
The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=a8676bf367b099dcc97ff61031cbf4ceb5e37899 commit a8676bf367b099dcc97ff61031cbf4ceb5e37899 Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2023-10-16 23:25:25 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2023-10-16 23:25:25 +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 --- 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 b6c81ad9fc25..6a216f31161b 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++;