The bootcache header has 12-character fields for date and time.
However, the __DATE__ string is only 9 characters long incl. null
terminator. When comparing __DATE__ and __TIME__ to the header's
fields, we should use the lengths of __DATE__ and __TIME__, because they
are <= 12 (size of the header fields).
e.g.
strncmp(hdr->date, __DATE__, sizeof(hdr->date))
--> sizeof(hdr->date) is 12 but __DATE__ is only 9 characters long,
so will throw a smatch error.
strncmp(hdr->date, __DATE__, strlen(__DATE__) + 1)
--> strlen(__DATE__) + 1 == 9, so this will not result in comparing
a string that is shorter than the required length.
BUG=chromium-os:37656
TEST=Build kernel with USE=test, after this CL has been merged:
https://gerrit.chromium.org/gerrit/#/c/40054/
dm-bootcache.c should not throw any smatch errors about strncmp().
Change-Id: I88c7cbb96dc4da611b96609ef21b3787483c25db
Signed-off-by: Simon Que <sque@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/40549
Reviewed-by: Paul Taysom <taysom@chromium.org>
return 0;
if (hdr->max_hw_sectors != cache->hdr.max_hw_sectors)
return 0;
- if (strncmp(hdr->date, __DATE__, sizeof(hdr->date)) != 0)
+ if (strncmp(hdr->date, __DATE__, strlen(__DATE__) + 1) != 0)
return 0;
- if (strncmp(hdr->time, __TIME__, sizeof(hdr->time)) != 0)
+ if (strncmp(hdr->time, __TIME__, strlen(__TIME__) + 1) != 0)
return 0;
if (strncmp(hdr->signature, cache->hdr.signature,
sizeof(hdr->signature)) != 0)