bugfix: ipmi: set dataLen to zero when appropriate

On failures (or some silent success), set the return
buffer length to 0.

Change-Id: I118788ffddd2bfc031b3392db4cf13ab04b49287
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/ipmi.cpp b/ipmi.cpp
index e2e0fef..92955f9 100644
--- a/ipmi.cpp
+++ b/ipmi.cpp
@@ -99,6 +99,7 @@
     /* Verify datalen is >= sizeof(request) */
     struct BmcBlobEnumerateTx request;
     auto reply = reinterpret_cast<struct BmcBlobEnumerateRx*>(replyCmdBuf);
+    (*dataLen) = 0;
 
     std::memcpy(&request, reqBuf, sizeof(request));
 
@@ -125,6 +126,7 @@
     size_t requestLen = (*dataLen);
     auto request = reinterpret_cast<const struct BmcBlobOpenTx*>(reqBuf);
     uint16_t session;
+    (*dataLen) = 0;
 
     std::string path = stringFromBuffer(
         request->blobId, (requestLen - sizeof(struct BmcBlobOpenTx)));
@@ -154,6 +156,7 @@
 {
     struct BmcBlobCloseTx request;
     std::memcpy(&request, reqBuf, sizeof(request));
+    (*dataLen) = 0;
 
     /* Attempt to close. */
     if (!mgr->close(request.sessionId))
@@ -161,7 +164,6 @@
         return IPMI_CC_UNSPECIFIED_ERROR;
     }
 
-    (*dataLen) = 0;
     return IPMI_CC_OK;
 }
 
@@ -170,6 +172,7 @@
 {
     size_t requestLen = (*dataLen);
     auto request = reinterpret_cast<const struct BmcBlobDeleteTx*>(reqBuf);
+    (*dataLen) = 0;
 
     std::string path = stringFromBuffer(
         request->blobId, (requestLen - sizeof(struct BmcBlobDeleteTx)));
@@ -184,7 +187,6 @@
         return IPMI_CC_UNSPECIFIED_ERROR;
     }
 
-    (*dataLen) = 0;
     return IPMI_CC_OK;
 }
 
@@ -215,6 +217,7 @@
 {
     size_t requestLen = (*dataLen);
     auto request = reinterpret_cast<const struct BmcBlobStatTx*>(reqBuf);
+    (*dataLen) = 0;
 
     std::string path = stringFromBuffer(
         request->blobId, (requestLen - sizeof(struct BmcBlobStatTx)));
@@ -238,6 +241,7 @@
 {
     struct BmcBlobSessionStatTx request;
     std::memcpy(&request, reqBuf, sizeof(request));
+    (*dataLen) = 0;
 
     /* Attempt to stat. */
     struct BlobMeta meta;
@@ -255,6 +259,7 @@
 {
     size_t requestLen = (*dataLen);
     auto request = reinterpret_cast<const struct BmcBlobCommitTx*>(reqBuf);
+    (*dataLen) = 0;
 
     /* Sanity check the commitDataLen */
     if (request->commitDataLen > (requestLen - sizeof(struct BmcBlobCommitTx)))
@@ -270,7 +275,6 @@
         return IPMI_CC_UNSPECIFIED_ERROR;
     }
 
-    (*dataLen) = 0;
     return IPMI_CC_OK;
 }
 
@@ -308,6 +312,7 @@
 {
     size_t requestLen = (*dataLen);
     auto request = reinterpret_cast<const struct BmcBlobWriteTx*>(reqBuf);
+    (*dataLen) = 0;
 
     uint32_t size = requestLen - sizeof(struct BmcBlobWriteTx);
     std::vector<uint8_t> data(size);
@@ -328,6 +333,7 @@
 {
     size_t requestLen = (*dataLen);
     struct BmcBlobWriteMetaTx request;
+    (*dataLen) = 0;
 
     /* Copy over the request. */
     std::memcpy(&request, reqBuf, sizeof(request));
diff --git a/main.cpp b/main.cpp
index 7bbae28..bc93ddd 100644
--- a/main.cpp
+++ b/main.cpp
@@ -53,6 +53,7 @@
         validateBlobCommand(&crc, reqBuf, replyCmdBuf, dataLen, &rc);
     if (command == nullptr)
     {
+        (*dataLen) = 0;
         return rc;
     }