]> xenbits.xensource.com Git - people/aperard/linux-chromebook.git/commitdiff
CHROMIUM: md: fix dm-bootcache string compare length
authorSimon Que <sque@chromium.org>
Mon, 7 Jan 2013 21:01:28 +0000 (13:01 -0800)
committerChromeBot <chrome-bot@google.com>
Mon, 7 Jan 2013 22:31:55 +0000 (14:31 -0800)
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>
drivers/md/dm-bootcache.c

index 9a4dc104b1d47bd0155586256a9df7bf50a6ede9..d83337d47e5a8ee8fcf55e051ac9dcf55d9dbc4c 100644 (file)
@@ -727,9 +727,9 @@ static int is_valid_hdr(struct bootcache *cache, struct bootcache_hdr *hdr)
                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)