diff options
author | Patrick Georgi <pgeorgi@google.com> | 2020-06-29 17:15:25 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-02-26 03:33:34 +0000 |
commit | 323b44830c3b36d7b82434f74db3bb6338e7a6ae (patch) | |
tree | 4e4ebeedf2ad9591a1db0429ac0b1e617b127ae9 | |
parent | cfee776155e8499d427761e2788190049217917a (diff) | |
download | chrome-ec-323b44830c3b36d7b82434f74db3bb6338e7a6ae.tar.gz |
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 <pgeorgi@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2273240
Tested-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
Commit-Queue: Patrick Georgi <pgeorgi@chromium.org>
(cherry picked from commit 3a838d11ae131526b1524a03789f11300f095c9b)
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2721093
Commit-Queue: Tim Wawrzynczak <twawrzynczak@chromium.org>
Tested-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
-rw-r--r-- | util/ecst.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/util/ecst.c b/util/ecst.c index 22f9f6c0e8..ea93a15104 100644 --- a/util/ecst.c +++ b/util/ecst.c @@ -393,7 +393,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], |