aboutsummaryrefslogtreecommitdiff
path: root/core/nvram-format.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/nvram-format.c')
-rw-r--r--core/nvram-format.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/core/nvram-format.c b/core/nvram-format.c
index 227147e..b98aee1 100644
--- a/core/nvram-format.c
+++ b/core/nvram-format.c
@@ -208,12 +208,27 @@ static const char *find_next_key(const char *start, const char *end)
*/
const char *nvram_query(const char *key)
{
- const char *part_end = (const char *) skiboot_part_hdr +
- skiboot_part_hdr->len * 16 - 1;
- const char *start = (const char *) skiboot_part_hdr +
- sizeof(*skiboot_part_hdr);
+ const char *part_end, *start;
int key_len = strlen(key);
+ /*
+ * The running OS can modify the NVRAM as it pleases so we need to be
+ * a little paranoid and check that it's ok before we try parse it.
+ *
+ * NB: nvram_validate() can update skiboot_part_hdr
+ */
+ if (!nvram_validate()) {
+ prerror("NVRAM: Look up for '%s' failed due to bad format!\n",
+ key);
+ return NULL;
+ }
+
+ part_end = (const char *) skiboot_part_hdr
+ + skiboot_part_hdr->len * 16 - 1;
+
+ start = (const char *) skiboot_part_hdr
+ + sizeof(*skiboot_part_hdr);
+
if (!key_len) {
prlog(PR_WARNING, "NVRAM: search key is empty!\n");
return NULL;