msgbuf: Return -EOVERFLOW where relevant in pldm_msgbuf_consumed()

-EBADMSG seems less appropriate for access patterns known to exceed
buffer limits.

Change-Id: I3051323cad0ec126c0fe5073902fcc50f8ff18a0
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/src/msgbuf.h b/src/msgbuf.h
index 437b423..cf30bad 100644
--- a/src/msgbuf.h
+++ b/src/msgbuf.h
@@ -144,17 +144,23 @@
  * @param[in] ctx - pldm_msgbuf context for extractor
  *
  * @return 0 iff there are zero bytes of data that remain unread from the buffer
- * and no overflow has occurred. Otherwise, -EBADMSG.
+ * and no overflow has occurred. Otherwise, -EBADMSG if the buffer has not been
+ * completely consumed, or -EOVERFLOW if accesses were attempted beyond the
+ * bounds of the buffer.
  */
 LIBPLDM_CC_NONNULL
 LIBPLDM_CC_ALWAYS_INLINE
 LIBPLDM_CC_WARN_UNUSED_RESULT
 int pldm_msgbuf_consumed(struct pldm_msgbuf *ctx)
 {
-	if (ctx->remaining != 0) {
+	if (ctx->remaining > 0) {
 		return -EBADMSG;
 	}
 
+	if (ctx->remaining < 0) {
+		return -EOVERFLOW;
+	}
+
 	return 0;
 }
 
@@ -187,7 +193,9 @@
  * @param[in] ctx - pldm_msgbuf context
  *
  * @return 0 if all buffer access were in-bounds and completely consume the
- * underlying buffer. Otherwise, -EBADMSG.
+ * underlying buffer. Otherwise, -EBADMSG if the buffer has not been completely
+ * consumed, or -EOVERFLOW if accesses were attempted beyond the bounds of the
+ * buffer.
  */
 LIBPLDM_CC_NONNULL
 LIBPLDM_CC_ALWAYS_INLINE