Skip to content

Commit 7ee61ee

Browse files
rizlikdanielinux
authored andcommitted
disk.c: fix: off-by-one argument checking
1 parent 2c9e586 commit 7ee61ee

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/disk.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ int disk_open(int drv)
117117
uint32_t gpt_lba = 0;
118118
uint8_t sector[GPT_SECTOR_SIZE] XALIGNED(4);
119119

120-
if ((drv < 0) || (drv > MAX_DISKS)) {
120+
if ((drv < 0) || (drv >= MAX_DISKS)) {
121121
wolfBoot_printf("Attempting to access invalid drive %d\r\n", drv);
122122
return -1;
123123
}
@@ -231,11 +231,11 @@ int disk_open(int drv)
231231
*/
232232
static struct disk_partition *open_part(int drv, int part)
233233
{
234-
if ((drv < 0) || (drv > MAX_DISKS)) {
234+
if ((drv < 0) || (drv >= MAX_DISKS)) {
235235
wolfBoot_printf("Attempting to access invalid drive %d\r\n", drv);
236236
return NULL;
237237
}
238-
if ((part < 0) || (part > MAX_PARTITIONS)) {
238+
if ((part < 0) || (part >= MAX_PARTITIONS)) {
239239
wolfBoot_printf("Attempting to access invalid partition %d\r\n", part);
240240
return NULL;
241241
}
@@ -344,7 +344,7 @@ int disk_find_partition_by_label(int drv, const char *label)
344344
struct disk_partition *p;
345345
int i;
346346

347-
if ((drv < 0) || (drv > MAX_DISKS)) {
347+
if ((drv < 0) || (drv >= MAX_DISKS)) {
348348
return -1;
349349
}
350350
if (Drives[drv].is_open == 0) {

0 commit comments

Comments
 (0)