diff --git a/plugins/ocp/ocp-hardware-component-log.c b/plugins/ocp/ocp-hardware-component-log.c index 2fb5fe256..92fa42f7f 100644 --- a/plugins/ocp/ocp-hardware-component-log.c +++ b/plugins/ocp/ocp-hardware-component-log.c @@ -171,6 +171,9 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log) { int ret = 0; size_t desc_offset = offsetof(struct hwcomp_log, desc); + long double log_bytes; + nvme_uint128_t log_size; + struct nvme_get_log_args args = { .args_size = sizeof(args), .fd = dev_fd(dev), @@ -193,16 +196,27 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log) } #endif /* HWCOMP_DUMMY */ + log_size = le128_to_cpu(log->size); + print_info("id: %02Xh\n", OCP_LID_HWCOMP); print_info("version: %04Xh\n", log->ver); print_info_array("guid", log->guid, ARRAY_SIZE(log->guid)); - print_info("size: %s\n", uint128_t_to_string(le128_to_cpu(log->size))); + print_info("size: %s\n", uint128_t_to_string(log_size)); + + log_bytes = uint128_t_to_double(log_size); + if (log->ver == 1) + log_bytes *= sizeof(__le32); + + args.len = 0; + if (log_bytes > desc_offset) + args.len = log_bytes - desc_offset; + + if (!args.len) { + print_info_error("error: ocp: invalid hwcomp log size bytes: %.0Lf\n", log_bytes); + return -EINVAL; + } - if (log->ver > 1) - args.len = uint128_t_to_double(le128_to_cpu(log->size)) - desc_offset; - else - args.len = uint128_t_to_double(le128_to_cpu(log->size)) * sizeof(__le32) - - desc_offset; + print_info("args.len: %u\n", args.len); log->desc = calloc(1, args.len); if (!log->desc) {