From 7f2d7c90a27aacb45fa5ccc18c777593e007d2a7 Mon Sep 17 00:00:00 2001 From: Nagaraju Goruganti Date: Wed, 21 Mar 2018 11:18:30 -0500 Subject: Fixed broken "fru read" command Fixed below given two issues: 1.We are getting seg-fault due to incorrect format specifiers for log-entry. 2.When requested data count plus offset exceeds fruArea size, we through error, instead we can return remaining bytes. Tested: 1.Verified using below given command. ipmitool -I lanplus -C 3 -P 0penBmc -H fru read fru_file Resolves openbmc/openbmc#2893 Change-Id: Iecfe80ed7230b936eca86fd16208582ee7b4e09c Signed-off-by: Nagaraju Goruganti --- storagehandler.cpp | 29 ++++++++++++++--------------- storagehandler.h | 9 +++++++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/storagehandler.cpp b/storagehandler.cpp index fa630e3..b222fa7 100644 --- a/storagehandler.cpp +++ b/storagehandler.cpp @@ -640,32 +640,31 @@ ipmi_ret_t ipmi_storage_read_fru_data( { ipmi_ret_t rc = IPMI_CC_OK; const ReadFruDataRequest* reqptr = - reinterpret_cast(request); + reinterpret_cast(request); + auto resptr = + reinterpret_cast(response); auto offset = static_cast(reqptr->offsetMS << 8 | reqptr->offsetLS); try { const auto& fruArea = getFruAreaData(reqptr->fruID); auto size = fruArea.size(); - if ((offset + reqptr->count) > size) + + // Write the count of response data. + if ((offset + reqptr->count) <= size) { - log("Invalid offset and count", - entry("OFFSET=%s", offset), - entry("COUNT=%s", reqptr->count), - entry("SIZE_OF_FRU_AREA=%s", size)); - return IPMI_CC_INVALID; + resptr->count = reqptr->count; + } + else + { + resptr->count = size - offset; } - - // Write the count of requested data. - auto buff = static_cast(response); - *buff = reqptr->count; - buff++; std::copy((fruArea.begin() + offset), - (fruArea.begin() + offset + reqptr->count), - buff); + (fruArea.begin() + offset + resptr->count), + resptr->data); - *data_len = reqptr->count + 1; // additional one byte for count + *data_len = resptr->count + 1; // additional one byte for count } catch (const InternalFailure& e) { diff --git a/storagehandler.h b/storagehandler.h index 1849fc7..009b281 100644 --- a/storagehandler.h +++ b/storagehandler.h @@ -45,6 +45,15 @@ struct ReadFruDataRequest uint8_t count; ///< Count to read }__attribute__ ((packed)); +/** + * @struct Read FRU Data command response data + */ +struct ReadFruDataResponse +{ + uint8_t count; ///< Response data Count. + uint8_t data[]; ///< Response data. +}__attribute__ ((packed)); + /** * @struct Get FRU inventory area info command request data */ -- cgit v1.2.1