diff options
author | John Baldwin <jhb@FreeBSD.org> | 2023-10-16 23:25:15 +0000 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2023-10-16 23:25:15 +0000 |
commit | 51749e05e96eb07134a38984a8c06608b20f07ea (patch) | |
tree | f472b4af8f3b0a8921312ff4208ad10052025974 /usr.sbin/bsdinstall/partedit | |
parent | ae2fc74fe76ca8b89c5ef0081ef3f4008f83de41 (diff) |
bsdinstall partedit: Replace malloc + sprintf with asprintf
This avoids potential bugs with the length passed to malloc not
matching the string written via sprintf.
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D42238
Diffstat (limited to 'usr.sbin/bsdinstall/partedit')
-rw-r--r-- | usr.sbin/bsdinstall/partedit/gpart_ops.c | 10 | ||||
-rw-r--r-- | usr.sbin/bsdinstall/partedit/partedit.c | 4 |
2 files changed, 5 insertions, 9 deletions
diff --git a/usr.sbin/bsdinstall/partedit/gpart_ops.c b/usr.sbin/bsdinstall/partedit/gpart_ops.c index 7f34819a3d4d..7395030b26aa 100644 --- a/usr.sbin/bsdinstall/partedit/gpart_ops.c +++ b/usr.sbin/bsdinstall/partedit/gpart_ops.c @@ -732,18 +732,16 @@ set_default_part_metadata(const char *name, const char *scheme, } if (newfs != NULL && newfs[0] != '\0') { - md->newfs = malloc(strlen(newfs) + strlen(" /dev/") + - strlen(mountpoint) + 5 + strlen(name) + 1); if (strcmp("freebsd-zfs", type) == 0) { zpool_name = strdup((strlen(mountpoint) == 1) ? "root" : &mountpoint[1]); for (i = 0; zpool_name[i] != 0; i++) if (!isalnum(zpool_name[i])) zpool_name[i] = '_'; - sprintf(md->newfs, "%s %s /dev/%s", newfs, + asprintf(&md->newfs, "%s %s /dev/%s", newfs, zpool_name, name); } else { - sprintf(md->newfs, "%s /dev/%s", newfs, name); + asprintf(&md->newfs, "%s /dev/%s", newfs, name); } } } @@ -780,9 +778,7 @@ set_default_part_metadata(const char *name, const char *scheme, if (strcmp("freebsd-zfs", type) == 0) { md->fstab->fs_spec = strdup(zpool_name); } else { - md->fstab->fs_spec = malloc(strlen(name) + - strlen("/dev/") + 1); - sprintf(md->fstab->fs_spec, "/dev/%s", name); + asprintf(&md->fstab->fs_spec, "/dev/%s", name); } md->fstab->fs_file = strdup(mountpoint); /* Get VFS from text after freebsd-, if possible */ diff --git a/usr.sbin/bsdinstall/partedit/partedit.c b/usr.sbin/bsdinstall/partedit/partedit.c index bb2580789fe8..b6c81ad9fc25 100644 --- a/usr.sbin/bsdinstall/partedit/partedit.c +++ b/usr.sbin/bsdinstall/partedit/partedit.c @@ -360,8 +360,8 @@ apply_changes(struct gmesh *mesh) TAILQ_FOREACH(md, &part_metadata, metadata) { if (md->newfs != NULL) { char *item; - item = malloc(255); - sprintf(item, "Initializing %s", md->name); + + asprintf(&item, "Initializing %s", md->name); minilabel[i] = item; miniperc[i] = BSDDIALOG_MG_PENDING; i++; |