diff options
author | Aaron Massey <aaronmassey@google.com> | 2022-09-21 13:02:24 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-09-21 23:52:45 +0000 |
commit | 229b358f694febb91ac0265850da8c52df588bd8 (patch) | |
tree | c600563ba70e725edc0b8f9dd51153ca4e7fc7fe /zephyr/emul | |
parent | 00723fbf9789cdeb4e4cc5dca373236197a6a4b3 (diff) | |
download | chrome-ec-229b358f694febb91ac0265850da8c52df588bd8.tar.gz |
emul_smart_battery: Validate string property sizes
Add BUILD_ASSERTs to enforce that strings of sizes larger than
MAX_BLOCK_SIZE cannot be properties of the DT node that the
emul_smart_battery is emulating.
BRANCH=none
BUG=b:246652125
TEST=./twister --clobber -i -s zephyr/test/drivers/drivers.default -b
TEST=Above TEST with failing string property
Signed-off-by: Aaron Massey <aaronmassey@google.com>
Change-Id: I5c44be1bfd1ff183a5357ea947285662d467fffc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3910903
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Reviewed-by: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'zephyr/emul')
-rw-r--r-- | zephyr/emul/emul_smart_battery.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/zephyr/emul/emul_smart_battery.c b/zephyr/emul/emul_smart_battery.c index b3e8d62bcc..3f79ec2019 100644 --- a/zephyr/emul/emul_smart_battery.c +++ b/zephyr/emul/emul_smart_battery.c @@ -796,6 +796,14 @@ static int sbat_emul_init(const struct emul *emul, const struct device *parent) return 0; } +#define SMART_BATTERY_VALIDATE_STRING_PROPS_SIZE(n) \ + BUILD_ASSERT(sizeof(DT_INST_PROP(n, dev_chem)) - 1 <= MAX_BLOCK_SIZE); \ + BUILD_ASSERT(sizeof(DT_INST_PROP(n, mf_data)) - 1 <= MAX_BLOCK_SIZE); \ + BUILD_ASSERT(sizeof(DT_INST_PROP(n, mf_info)) - 1 <= MAX_BLOCK_SIZE); \ + BUILD_ASSERT(sizeof(DT_INST_PROP(n, mf_name)) - 1 <= MAX_BLOCK_SIZE); + +DT_INST_FOREACH_STATUS_OKAY(SMART_BATTERY_VALIDATE_STRING_PROPS_SIZE) + #define SMART_BATTERY_EMUL(n) \ static struct sbat_emul_data sbat_emul_data_##n = { \ .bat = { \ |