X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=diskutil.c;h=e29d1c34af24d116f9a601437adb798a8ec194cf;hp=d98e39a50b0d6423febdf0457f5097718ad53382;hb=d2507043dbe51b657f25a0149c1f64a794e18b47;hpb=73cfb8a7da365c37253662477edb54ecc19575df diff --git a/diskutil.c b/diskutil.c index d98e39a5..e29d1c34 100644 --- a/diskutil.c +++ b/diskutil.c @@ -276,13 +276,25 @@ static struct disk_util *disk_util_add(struct thread_data *td, int majdev, { struct disk_util *du, *__du; struct flist_head *entry; + int l; dprint(FD_DISKUTIL, "add maj/min %d/%d: %s\n", majdev, mindev, path); du = smalloc(sizeof(*du)); + if (!du) { + log_err("fio: smalloc() pool exhausted\n"); + return NULL; + } + memset(du, 0, sizeof(*du)); INIT_FLIST_HEAD(&du->list); - sprintf(du->path, "%s/stat", path); + l = snprintf(du->path, sizeof(du->path), "%s/stat", path); + if (l < 0 || l >= sizeof(du->path)) { + log_err("constructed path \"%.100s[...]/stat\" larger than buffer (%zu bytes)\n", + path, sizeof(du->path) - 1); + sfree(du); + return NULL; + } strncpy((char *) du->dus.name, basename(path), FIO_DU_NAME_SZ); du->sysfs_root = path; du->major = majdev; @@ -658,7 +670,7 @@ void show_disk_util(int terse, struct json_object *parent) if (!terse) log_info("\nDisk stats (read/write):\n"); - if (terse && terse_version == 4) { + if (output_format == FIO_OUTPUT_JSON) { array = json_create_array(); json_object_add_value_array(parent, "disk_util", array); } @@ -667,7 +679,7 @@ void show_disk_util(int terse, struct json_object *parent) du = flist_entry(entry, struct disk_util, list); aggregate_slaves_stats(du); - if (terse && terse_version == 4) + if (output_format == FIO_OUTPUT_JSON) print_disk_util_json(du, array); else print_disk_util(&du->dus, &du->agg, terse);