Fix crash when SD card is smaller than starting sector of scsi disk
authorMichael McMaster <michael@codesrc.com>
Sat, 29 Apr 2017 04:40:25 +0000 (14:40 +1000)
committerMichael McMaster <michael@codesrc.com>
Sat, 29 Apr 2017 04:40:25 +0000 (14:40 +1000)
src/firmware/geometry.c

index 52e87b9..44a2e82 100755 (executable)
@@ -30,10 +30,16 @@ uint32_t getScsiCapacity(
        uint32_t capacity =\r
                (sdDev.capacity - sdSectorStart - S2S_CFG_SIZE) /\r
                        SDSectorsPerSCSISector(bytesPerSector);\r
        uint32_t capacity =\r
                (sdDev.capacity - sdSectorStart - S2S_CFG_SIZE) /\r
                        SDSectorsPerSCSISector(bytesPerSector);\r
+\r
+\r
        if (sdDev.capacity == 0)\r
        {\r
                capacity = 0;\r
        }\r
        if (sdDev.capacity == 0)\r
        {\r
                capacity = 0;\r
        }\r
+       else if (sdSectorStart >= (sdDev.capacity - S2S_CFG_SIZE))\r
+       {\r
+               capacity = 0;\r
+       }\r
        else if (scsiSectors && (capacity > scsiSectors))\r
        {\r
                capacity = scsiSectors;\r
        else if (scsiSectors && (capacity > scsiSectors))\r
        {\r
                capacity = scsiSectors;\r