Angel Pons has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/52637 )
Change subject: drivers/pc80/rtc/option.c: Constrain API to integer values ......................................................................
drivers/pc80/rtc/option.c: Constrain API to integer values
None of the options accessed within coreboot is a string, and there are no guarantees that the code works as intended with them. Given that the current option API only supports integers for now, do not try to access options whose type is 's' (string).
Change-Id: Ib67b126d972c6d55b77ea5ecfb862b4e9c766fe5 Signed-off-by: Angel Pons th3fanbus@gmail.com --- M src/drivers/pc80/rtc/option.c M src/include/option.h 2 files changed, 12 insertions(+), 16 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/37/52637/1
diff --git a/src/drivers/pc80/rtc/option.c b/src/drivers/pc80/rtc/option.c index 5cc5ea5..724ec8d 100644 --- a/src/drivers/pc80/rtc/option.c +++ b/src/drivers/pc80/rtc/option.c @@ -84,7 +84,7 @@ return NULL; }
-enum cb_err cmos_get_option(void *dest, const char *name) +enum cb_err cmos_get_int_option(int *dest, const char *name) { struct cmos_option_table *ct; struct cmos_entries *ce; @@ -99,6 +99,9 @@ return CB_CMOS_OPTION_NOT_FOUND; }
+ if (ce->config == 's') + return CB_ERR_ARG; + if (!cmos_checksum_valid(LB_CKS_RANGE_START, LB_CKS_RANGE_END, LB_CKS_LOC)) return CB_CMOS_CHECKSUM_INVALID;
@@ -149,11 +152,10 @@ return CB_SUCCESS; }
-enum cb_err cmos_set_option(const char *name, void *value) +enum cb_err cmos_set_int_option(const char *name, int *value) { struct cmos_option_table *ct; struct cmos_entries *ce; - unsigned long length;
ct = get_cmos_layout(); if (!ct) @@ -165,16 +167,10 @@ return CB_CMOS_OPTION_NOT_FOUND; }
- length = ce->length; - if (ce->config == 's') { - length = MAX(strlen((const char *)value) * 8, ce->length - 8); - /* make sure the string is null terminated */ - if (set_cmos_value(ce->bit + ce->length - 8, 8, &(u8[]){0}) - != CB_SUCCESS) - return CB_CMOS_ACCESS_ERROR; - } + if (ce->config == 's') + return CB_ERR_ARG;
- if (set_cmos_value(ce->bit, length, value) != CB_SUCCESS) + if (set_cmos_value(ce->bit, ce->length, value) != CB_SUCCESS) return CB_CMOS_ACCESS_ERROR;
return CB_SUCCESS; diff --git a/src/include/option.h b/src/include/option.h index 4de032b..dd461c1 100644 --- a/src/include/option.h +++ b/src/include/option.h @@ -7,13 +7,13 @@
void sanitize_cmos(void);
-enum cb_err cmos_set_option(const char *name, void *val); -enum cb_err cmos_get_option(void *dest, const char *name); +enum cb_err cmos_set_int_option(const char *name, int *value); +enum cb_err cmos_get_int_option(int *dest, const char *name);
static inline enum cb_err set_int_option(const char *name, int value) { if (CONFIG(USE_OPTION_TABLE)) - return cmos_set_option(name, &value); + return cmos_set_int_option(name, &value);
return CB_CMOS_OTABLE_DISABLED; } @@ -22,7 +22,7 @@ { if (CONFIG(USE_OPTION_TABLE)) { int value = 0; - if (cmos_get_option(&value, name) == CB_SUCCESS) + if (cmos_get_int_option(&value, name) == CB_SUCCESS) return value; } return fallback;