diff options
author | Tom Hughes <tomhughes@chromium.org> | 2022-07-11 10:21:49 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-07-13 15:46:35 +0000 |
commit | c8282f61e105490ed50120ec2d6a83a1e2ec1e08 (patch) | |
tree | 73047f4ef11b26e46ef90795a1c74c3c03932394 /chip/host | |
parent | cce493a388878334a65af95c4313ee051ef8a546 (diff) | |
download | chrome-ec-c8282f61e105490ed50120ec2d6a83a1e2ec1e08.tar.gz |
tree: Check return value from snprintf
snprintf returns a negative value on failure. The return value should be
checked to make sure that there were no errors.
BRANCH=none
BUG=b:238433667, b:234181908
TEST=make buildall
Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Change-Id: I64e2e69df7fa22c94f19acbbca8c6afbe6cf1ff1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3756174
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'chip/host')
-rw-r--r-- | chip/host/persistence.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/chip/host/persistence.c b/chip/host/persistence.c index b2ab19f97e..d23615d1ec 100644 --- a/chip/host/persistence.c +++ b/chip/host/persistence.c @@ -62,6 +62,8 @@ static void get_storage_path(char *out) sz = snprintf(out, PATH_MAX - 1, "/dev/shm/EC_persist_%.*s", max_len, buf); + ASSERT(sz > 0); + out[PATH_MAX - 1] = '\0'; ASSERT(sz <= max_len + max_prefix_len); @@ -71,6 +73,7 @@ FILE *get_persistent_storage(const char *tag, const char *mode) { char buf[PATH_MAX]; char path[PATH_MAX]; + int sz; /* There's no longer tag in use right now, and there shouldn't be. */ ASSERT(strlen(tag) < 32); @@ -80,8 +83,9 @@ FILE *get_persistent_storage(const char *tag, const char *mode) * be named 'bar_persist_foo' */ get_storage_path(buf); - snprintf(path, PATH_MAX - 1, "%.*s_%32s", max_len + max_prefix_len, buf, - tag); + sz = snprintf(path, PATH_MAX - 1, "%.*s_%32s", max_len + max_prefix_len, + buf, tag); + ASSERT(sz > 0); path[PATH_MAX - 1] = '\0'; return fopen(path, mode); @@ -96,13 +100,15 @@ void remove_persistent_storage(const char *tag) { char buf[PATH_MAX]; char path[PATH_MAX]; + int sz; /* There's no longer tag in use right now, and there shouldn't be. */ ASSERT(strlen(tag) < 32); get_storage_path(buf); - snprintf(path, PATH_MAX - 1, "%.*s_%32s", max_len + max_prefix_len, buf, - tag); + sz = snprintf(path, PATH_MAX - 1, "%.*s_%32s", max_len + max_prefix_len, + buf, tag); + ASSERT(sz > 0); path[PATH_MAX - 1] = '\0'; unlink(path); |