Skip to content

Commit 54b6b26

Browse files
committed
kpartx: dasd: avoid negative partition size
Make sure that size - sp[0].start does not result in a negative value. Found withe the help of Claude Sonnet 4.6. Signed-off-by: Martin Wilck <mwilck@suse.com> Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
1 parent d6be2e1 commit 54b6b26

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

kpartx/dasd.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int read_dasd_pt(int fd, __attribute__((unused)) struct slice all,
7171
int retval = -1;
7272
int blocksize;
7373
uint64_t disksize;
74-
uint64_t offset, size, fmt_size;
74+
uint64_t offset, size, fmt_size, start;
7575
dasd_information_t info;
7676
struct hd_geometry geo;
7777
char type[5] = {0,};
@@ -214,8 +214,11 @@ int read_dasd_pt(int fd, __attribute__((unused)) struct slice all,
214214
offset = info.label_block + 1;
215215
size = sectors512(label[8], blocksize);
216216
}
217-
sp[0].start = sectors512(offset, blocksize);
218-
sp[0].size = size - sp[0].start;
217+
start = sectors512(offset, blocksize);
218+
if (start >= size)
219+
goto out;
220+
sp[0].start = start;
221+
sp[0].size = size - start;
219222
retval = 1;
220223
} else if ((strncmp(type, "VOL1", 4) == 0) &&
221224
(!info.FBA_layout) && (!memcmp(info.type, "ECKD",4))) {
@@ -288,8 +291,11 @@ int read_dasd_pt(int fd, __attribute__((unused)) struct slice all,
288291
} else
289292
size = disksize;
290293

291-
sp[0].start = sectors512(info.label_block + 1, blocksize);
292-
sp[0].size = size - sp[0].start;
294+
start = sectors512(info.label_block + 1, blocksize);
295+
if (start >= size)
296+
goto out;
297+
sp[0].start = start;
298+
sp[0].size = size - start;
293299
retval = 1;
294300
}
295301

0 commit comments

Comments
 (0)