From 65ce016544a8b6c015cd538d2ab388f34dd09989 Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Mon, 29 Jun 2020 17:15:25 +0200 Subject: util/ecst: Make sure that copying back arguments doesn't exceed MAX_ARGS Newer gcc than we have in CrOS shows a non-helpful error message: util/ecst.c: In function 'main': util/ecst.c:398:7: error: 'strncpy' output may be truncated copying 100 bytes from a string of length 9999 [-Werror=stringop-truncation] 398 | strncpy(hdr_args[arg_ind++], | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ 399 | tmp_hdr_args[tmp_ind], | ~~~~~~~~~~~~~~~~~~~~~~ 400 | ARG_SIZE); | ~~~~~~~~~ In the end it's about gcc not being able to ensure that hdr_args[] doesn't overflow. BUG=none BRANCH=none TEST=gcc 9.3 as shipped with debian sid compiles ecst without error Change-Id: I2c30cdfaac0305ea4e4c19477469bcf497469caa Signed-off-by: Patrick Georgi Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2273240 Tested-by: Patrick Georgi Reviewed-by: Paul Fagerburg Commit-Queue: Patrick Georgi Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3105732 Reviewed-by: Jack Rosenthal Commit-Queue: Daisuke Nojiri Tested-by: Daisuke Nojiri --- util/ecst.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/ecst.c b/util/ecst.c index 328587e8d9..a46d444817 100755 --- a/util/ecst.c +++ b/util/ecst.c @@ -391,7 +391,8 @@ int main(int argc, char *argv[]) /* Copy back the restored arguments. */ for (tmp_ind = 0; - tmp_ind < tmp_arg_num; + (tmp_ind < tmp_arg_num) && + (arg_ind < MAX_ARGS); tmp_ind++) { strncpy(hdr_args[arg_ind++], tmp_hdr_args[tmp_ind], -- cgit v1.2.1