61 lines
1.8 KiB
Diff
61 lines
1.8 KiB
Diff
From 086e13c72651439f39f678ffefb4f78b0c0fb758 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali.rohar@gmail.com>
|
|
Date: Sun, 12 Aug 2018 12:15:21 +0200
|
|
Subject: [PATCH 82/86] mkfs.fat: Fix parsing of block number
|
|
|
|
Block number must not be negative. It is 32bit so use long long type and
|
|
strtoll() function to ensure that converted positive 32bit value would fit
|
|
into type.
|
|
---
|
|
src/mkfs.fat.c | 12 ++++++------
|
|
1 file changed, 6 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/src/mkfs.fat.c b/src/mkfs.fat.c
|
|
index 660b6ba..70f13c1 100644
|
|
--- a/src/mkfs.fat.c
|
|
+++ b/src/mkfs.fat.c
|
|
@@ -417,7 +417,7 @@ static void get_list_blocks(char *filename)
|
|
{
|
|
int i;
|
|
FILE *listfile;
|
|
- long blockno;
|
|
+ long long blockno;
|
|
char *line = NULL;
|
|
size_t linesize = 0;
|
|
int lineno = 0;
|
|
@@ -439,9 +439,9 @@ static void get_list_blocks(char *filename)
|
|
}
|
|
|
|
errno = 0;
|
|
- blockno = strtol(line, &end, 10);
|
|
+ blockno = strtoll(line, &end, 10);
|
|
|
|
- if (errno) {
|
|
+ if (errno || blockno < 0) {
|
|
fprintf(stderr,
|
|
"While converting bad block number in line %d: %s\n",
|
|
lineno, strerror(errno));
|
|
@@ -466,16 +466,16 @@ static void get_list_blocks(char *filename)
|
|
|
|
/* Mark all of the sectors in the block as bad */
|
|
for (i = 0; i < SECTORS_PER_BLOCK; i++) {
|
|
- unsigned long sector = blockno * SECTORS_PER_BLOCK + i;
|
|
+ unsigned long long sector = blockno * SECTORS_PER_BLOCK + i;
|
|
|
|
if (sector < start_data_sector) {
|
|
- fprintf(stderr, "Block number %ld is before data area\n",
|
|
+ fprintf(stderr, "Block number %lld is before data area\n",
|
|
blockno);
|
|
die("Error in bad blocks file");
|
|
}
|
|
|
|
if (sector >= num_sectors) {
|
|
- fprintf(stderr, "Block number %ld is behind end of filesystem\n",
|
|
+ fprintf(stderr, "Block number %lld is behind end of filesystem\n",
|
|
blockno);
|
|
die("Error in bad blocks file");
|
|
}
|
|
--
|
|
1.8.3.1
|
|
|