Message ID | 20180917052739.24751-1-vaibhav@linux.ibm.com |
---|---|
State | Accepted |
Headers | show |
Series | nvram: Fix a possible NULL pointer de-ref in nvram_query_eq() | expand |
Context | Check | Description |
---|---|---|
snowpatch_ozlabs/apply_patch | success | master/apply_patch Successfully applied |
snowpatch_ozlabs/make_check | success | Test make_check on branch master |
Vaibhav Jain <vaibhav@linux.ibm.com> writes: > A fault will occur if 'value == NULL' is passed to nvram_query_eq() to > check if a given key doesn't exists in nvram partition. This is an > invalid use of the API as its only supposed to be used for keys that > exist in nvram and 'value == NULL' is never possible. > > Hence this patch adds an assert to the function to flag such a use and > also prevent NULL being passed as an argument to strcmp(). > > Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com> > Suggested-by: Oliver O'Halloran <oohall@gmail.com> > --- > Change-log: > > v2 -> Instead of handling 'value == NULL' trigger an assert as > its an invalid use of the api. [Oliver] Thanks. Merged to master as of a6fca4819fd1cae4e9afc374ba2ed34495865f65
diff --git a/core/nvram-format.c b/core/nvram-format.c index 42c5cbbb..e2cb40f3 100644 --- a/core/nvram-format.c +++ b/core/nvram-format.c @@ -278,6 +278,14 @@ const char *nvram_query(const char *key) } +/* + * nvram_query_eq() - Check if the given 'key' exists and + * is set to 'value'. + * + * Note: Its an error to check for non-existence of a key + * by passing 'value == NULL' as a key's value can never be + * NULL in nvram. + */ bool nvram_query_eq(const char *key, const char *value) { const char *s = nvram_query(key); @@ -285,5 +293,6 @@ bool nvram_query_eq(const char *key, const char *value) if (!s) return false; + assert(value != NULL); return !strcmp(s, value); }
A fault will occur if 'value == NULL' is passed to nvram_query_eq() to check if a given key doesn't exists in nvram partition. This is an invalid use of the API as its only supposed to be used for keys that exist in nvram and 'value == NULL' is never possible. Hence this patch adds an assert to the function to flag such a use and also prevent NULL being passed as an argument to strcmp(). Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com> Suggested-by: Oliver O'Halloran <oohall@gmail.com> --- Change-log: v2 -> Instead of handling 'value == NULL' trigger an assert as its an invalid use of the api. [Oliver] --- core/nvram-format.c | 9 +++++++++ 1 file changed, 9 insertions(+)