From d12bfc33dcfb90c9eecdf5d35df46dc461c40faf Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 18 Jun 2019 10:15:06 -0700 Subject: [PATCH] wdc: Fix endianness bugs Insert le16_to_cpu() / le32_to_cpu() where required. Cc: Dong Ho Fixes: 6bd8ab436693 ("wdc: Add data area extraction for DUI command"). Signed-off-by: Bart Van Assche --- plugins/wdc/wdc-nvme.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/wdc/wdc-nvme.c b/plugins/wdc/wdc-nvme.c index a9c86b6e..ba90fc09 100644 --- a/plugins/wdc/wdc-nvme.c +++ b/plugins/wdc/wdc-nvme.c @@ -914,7 +914,8 @@ static bool get_dev_mgment_cbs_data(int fd, __u8 log_id, void **cbs_data) if (le32_to_cpu(hdr_ptr->length) > WDC_C2_LOG_BUF_LEN) { /* Log Page buffer too small, free and reallocate the necessary size */ free(data); - if ((data = (__u8*) calloc(hdr_ptr->length, sizeof (__u8))) == NULL) { + data = calloc(le32_to_cpu(hdr_ptr->length), sizeof(__u8)); + if (data == NULL) { fprintf(stderr, "ERROR : WDC : malloc : %s\n", strerror(errno)); return false; } @@ -1290,9 +1291,12 @@ static int wdc_do_cap_dui(int fd, char *file, __u32 xfer_size, int data_area) /* parse log header for all sections up to specified data area inclusively */ if (data_area != WDC_NVME_DUI_MAX_DATA_AREA) { for(int i = 0; i < WDC_NVME_DUI_MAX_SECTION; i++) { - if (log_hdr->log_section[i].data_area_id <= data_area && - log_hdr->log_section[i].data_area_id != 0) - log_size += log_hdr->log_section[i].section_size; + __u16 data_area_id = le16_to_cpu(log_hdr->log_section[i].data_area_id); + __u16 section_size = le16_to_cpu(log_hdr->log_section[i].section_size); + + if (data_area_id <= data_area && + data_area_id != 0) + log_size += section_size; else break; } -- 2.50.1