irda: Test index before read in stir421x_patch_device()
authorRoel Kluin <roel.kluin@gmail.com>
Mon, 4 Oct 2010 23:30:02 +0000 (01:30 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 11 Oct 2010 00:11:58 +0000 (02:11 +0200)
Test whether index exceeds fw->size before reading the element

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Signed-off-by: Samuel Ortiz <samuel@sortiz.org>
drivers/net/irda/irda-usb.c

index cce82f101f50bab3309b16a8e0b6898d452fe5f9..e4ea61944c22937a5a1e3309242467d0f7b4edc9 100644 (file)
@@ -1124,11 +1124,11 @@ static int stir421x_patch_device(struct irda_usb_cb *self)
                  * The actual image starts after the "STMP" keyword
                  * so forward to the firmware header tag
                  */
-                for (i = 0; (fw->data[i] != STIR421X_PATCH_END_OF_HDR_TAG) &&
-                            (i < fw->size); i++) ;
+                for (i = 0; i < fw->size && fw->data[i] !=
+                            STIR421X_PATCH_END_OF_HDR_TAG; i++) ;
                 /* here we check for the out of buffer case */
-                if ((STIR421X_PATCH_END_OF_HDR_TAG == fw->data[i]) &&
-                    (i < STIR421X_PATCH_CODE_OFFSET)) {
+                if (i < STIR421X_PATCH_CODE_OFFSET && i < fw->size &&
+                               STIR421X_PATCH_END_OF_HDR_TAG == fw->data[i]) {
                         if (!memcmp(fw->data + i + 1, STIR421X_PATCH_STMP_TAG,
                                     sizeof(STIR421X_PATCH_STMP_TAG) - 1)) {