altera-stapl: check for a null key before strcasecmp'ing it
authorColin Ian King <colin.king@canonical.com>
Sat, 24 Nov 2018 12:34:10 +0000 (12:34 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 27 Nov 2018 07:44:07 +0000 (08:44 +0100)
Currently the null check on key is occurring after the strcasecmp on
the key, hence there is a potential null pointer dereference on key.
Fix this by checking if key is null first. Also replace the == 0
check on strcasecmp with just the ! operator.

Detected by CoverityScan, CID#1248787 ("Dereference before null check")

Fixes: fa766c9be58b ("[media] Altera FPGA firmware download module")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/altera-stapl/altera.c

index ef83a90..d2ed3b9 100644 (file)
@@ -2176,8 +2176,7 @@ static int altera_get_note(u8 *p, s32 program_size,
                        key_ptr = &p[note_strings +
                                        get_unaligned_be32(
                                        &p[note_table + (8 * i)])];
-                       if ((strncasecmp(key, key_ptr, strlen(key_ptr)) == 0) &&
-                                               (key != NULL)) {
+                       if (key && !strncasecmp(key, key_ptr, strlen(key_ptr))) {
                                status = 0;
 
                                value_ptr = &p[note_strings +