summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2015-06-23 09:23:00 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2015-08-26 12:52:19 +0200
commitc170240d3e5fb5cd134790dfc0c6e474fc0e6706 (patch)
treee3fee9e49c89f93ee29dcc0f0764865d84d287c2
parent546c5a9c788eb63f3e3a0ed74f6498cc19c2b07d (diff)
downloadbarebox-c170240d3e5fb5cd134790dfc0c6e474fc0e6706.tar.gz
barebox-c170240d3e5fb5cd134790dfc0c6e474fc0e6706.tar.xz
param_enum: protect against invalid values
Since dev_add_param_enum is passed a pointer containing the actual value it can contain an invalid value. Protect against it so that we do not access invalid array elements. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--lib/parameter.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/parameter.c b/lib/parameter.c
index 868b810019..fd05b49adf 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -389,7 +389,7 @@ struct param_d *dev_add_param_int(struct device_d *dev, const char *name,
struct param_enum {
struct param_d param;
- int *value;
+ unsigned int *value;
const char * const *names;
int num_names;
int (*set)(struct param_d *p, void *priv);
@@ -441,7 +441,11 @@ static const char *param_enum_get(struct device_d *dev, struct param_d *p)
}
free(p->value);
- p->value = strdup(pe->names[*pe->value]);
+
+ if (*pe->value >= pe->num_names)
+ p->value = asprintf("invalid:%d", *pe->value);
+ else
+ p->value = strdup(pe->names[*pe->value]);
return p->value;
}