summaryrefslogtreecommitdiff
path: root/common/host_command.c
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2019-11-22 08:52:23 -0700
committerCommit Bot <commit-bot@chromium.org>2019-11-26 19:32:21 +0000
commit3842121022bc7a9f30a879f9715ff9d416eae7ba (patch)
treea190558dd8d4c5ceb55b706ff1600b668d6e6ca8 /common/host_command.c
parentbd7f034b6cf01380cc7e14f28c3bd72ad42daaf2 (diff)
downloadchrome-ec-3842121022bc7a9f30a879f9715ff9d416eae7ba.tar.gz
host_command: clear any leftover data
We want to ensure that the entire buffer we may be sending back to the host from the EC does not contain any data from previous host command responses. Clear the data in common code so all chips do not have to implement this functionality. BRANCH=none BUG=b:144878983,chromium:1026994 TEST=new unit test shows cleared data Change-Id: I93ad4d36923ba1bf171f740e94830640d3fde3b0 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1930931
Diffstat (limited to 'common/host_command.c')
-rw-r--r--common/host_command.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/common/host_command.c b/common/host_command.c
index eff1fac56b..c3a207937e 100644
--- a/common/host_command.c
+++ b/common/host_command.c
@@ -681,6 +681,20 @@ uint16_t host_command_process(struct host_cmd_handler_args *args)
if (hcdebug)
host_command_debug_request(args);
+ /*
+ * Pre-emptively clear the entire response buffer so we do not
+ * have any left over contents from previous host commands.
+ * For example, this prevents the last portion of a char array buffer
+ * from containing data from the last host command if the string does
+ * not take the entire width of the char array buffer.
+ *
+ * Note that if request and response buffers pointed to the same memory
+ * location, then the chip implementation already needed to provide a
+ * request_temp buffer in which the request data was already copied
+ * by this point (see host_packet_receive function).
+ */
+ memset(args->response, 0, args->response_max);
+
#ifdef CONFIG_HOSTCMD_PD
if (args->command >= EC_CMD_PASSTHRU_OFFSET(1) &&
args->command <= EC_CMD_PASSTHRU_MAX(1)) {