Skip to contentSkip to conversation

command: hashsum: md5sum reports wrong sum for the file named 4k.bin

PATCH Superseded Peter Mamonov 2 participants 13 messages Dec 20, 2017 – Jan 17, 2018 Library code

lore
Share & tools
lore
#0 lore raw

Hi,

The md5sum command reports wrong sum for a file named 4k.bin and, I guess, for other files named alike. Here are the commands to reproduce the bug:

barebox@barebox sandbox:/ memcpy -s /dev/zero -d _4k.bin 0 0 4k barebox@barebox sandbox:/ md5sum _4k.bin 620f0b67a91f7f74151bc5be745b7110 _4k.bin

barebox@barebox sandbox:/ cp _4k.bin 4k.bin barebox@barebox sandbox:/ md5sum 4k.bin d41d8cd98f00b204e9800998ecf8427e 4k.bin

barebox@barebox sandbox:/ cp 4k.bin __4k.bin barebox@barebox sandbox:/ md5sum __4k.bin 620f0b67a91f7f74151bc5be745b7110 __4k.bin

barebox@barebox sandbox:/ version

barebox 2017.12.0 #4 Wed Dec 20 12:26:57 MSK 2017

barebox@barebox sandbox:/ Terminated

$ dd if=/dev/zero bs=4k count=1 | md5sum
...
620f0b67a91f7f74151bc5be745b7110 -

Regards,
Peter

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw
Quoted 4 lines · Peter Mamonov

Hi,

The md5sum command reports wrong sum for a file named 4k.bin and, I guess, for other files named alike. Here are the commands to reproduce the bug:

The problem lays in __do_digest() function:
- it initializes variables start and size at commands/digest.c:38
- then it calls parse_area_spec(*argv, &start, &size) at commands/digest.c:42
- parse_area_spec() returns error as it should, however it changes the value of the start at lib/misc.c:87.
- this causes digest algo to skip leading 4k of the data from the file.

I'm not quite sure what is the best solution:
- prevent parse_area_spec() from setting start if it fails?
- reinitialize start/size after unsuccessfull call to parse_area_spec()?

Regards,
Peter

Quoted 17 lines

barebox@barebox sandbox:/ memcpy -s /dev/zero -d _4k.bin 0 0 4k barebox@barebox sandbox:/ md5sum _4k.bin 620f0b67a91f7f74151bc5be745b7110 _4k.bin

barebox@barebox sandbox:/ cp _4k.bin 4k.bin barebox@barebox sandbox:/ md5sum 4k.bin d41d8cd98f00b204e9800998ecf8427e 4k.bin

barebox@barebox sandbox:/ cp 4k.bin __4k.bin barebox@barebox sandbox:/ md5sum __4k.bin 620f0b67a91f7f74151bc5be745b7110 __4k.bin

barebox@barebox sandbox:/ version

barebox 2017.12.0 #4 Wed Dec 20 12:26:57 MSK 2017

Quoted 8 lines

barebox@barebox sandbox:/ Terminated

$ dd if=/dev/zero bs=4k count=1 | md5sum
...
620f0b67a91f7f74151bc5be745b7110 -

Regards,
Peter

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#2 lore raw

Hi Peter,

Quoted 13 lines · Peter Mamonov
Quoted 4 lines · Peter Mamonov

Hi,

The md5sum command reports wrong sum for a file named 4k.bin and, I guess, for other files named alike. Here are the commands to reproduce the bug:

The problem lays in __do_digest() function:
- it initializes variables start and size at commands/digest.c:38
- then it calls parse_area_spec(*argv, &start, &size) at commands/digest.c:42
- parse_area_spec() returns error as it should, however it changes the value of the start at lib/misc.c:87.
- this causes digest algo to skip leading 4k of the data from the file.

Quoted 3 lines

I'm not quite sure what is the best solution:
- prevent parse_area_spec() from setting start if it fails?
- reinitialize start/size after unsuccessfull call to parse_area_spec()?

preventing parse_area_spec() from modifying start and size if it fails seems like a good idea.

However, this doesn't solve the problem, does it? parse_area_spec() only fails because the dot in 4k.bin is not valid, but if you name the file only '4k' then parse_area_spec() won't fail.
The problem is that we cannot know whether '4k' is a file or an area.

Right now I have no good idea how to make the command nonambiguous, but this will require an incompatible change to the commands arguments.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw
Quoted 20 lines · Sascha Hauer

Hi Peter,

Quoted 13 lines · Peter Mamonov
Quoted 4 lines · Peter Mamonov

Hi,

The md5sum command reports wrong sum for a file named 4k.bin and, I guess, for other files named alike. Here are the commands to reproduce the bug:

The problem lays in __do_digest() function:
- it initializes variables start and size at commands/digest.c:38
- then it calls parse_area_spec(*argv, &start, &size) at commands/digest.c:42
- parse_area_spec() returns error as it should, however it changes the value of the start at lib/misc.c:87.
- this causes digest algo to skip leading 4k of the data from the file.

Quoted 3 lines

I'm not quite sure what is the best solution:
- prevent parse_area_spec() from setting start if it fails?
- reinitialize start/size after unsuccessfull call to parse_area_spec()?

Quoted 7 lines

preventing parse_area_spec() from modifying start and size if it fails seems like a good idea.

However, this doesn't solve the problem, does it? parse_area_spec() only fails because the dot in 4k.bin is not valid, but if you name the file only '4k' then parse_area_spec() won't fail.
The problem is that we cannot know whether '4k' is a file or an area.

You are right. However, there is no ambiguity in the "4k.bin" and similar cases, so we can fix at least this obvious problem.

Regards,
Peter

Quoted 12 lines

Right now I have no good idea how to make the command nonambiguous, but this will require an incompatible change to the commands arguments.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw
Quoted 24 lines · Peter Mamonov
Quoted 23 lines · Sascha Hauer

Hi Peter,

Quoted 13 lines · Peter Mamonov
Quoted 4 lines · Peter Mamonov

Hi,

The md5sum command reports wrong sum for a file named 4k.bin and, I guess, for other files named alike. Here are the commands to reproduce the bug:

The problem lays in __do_digest() function:
- it initializes variables start and size at commands/digest.c:38
- then it calls parse_area_spec(*argv, &start, &size) at commands/digest.c:42
- parse_area_spec() returns error as it should, however it changes the value of the start at lib/misc.c:87.
- this causes digest algo to skip leading 4k of the data from the file.

Quoted 3 lines

I'm not quite sure what is the best solution:
- prevent parse_area_spec() from setting start if it fails?
- reinitialize start/size after unsuccessfull call to parse_area_spec()?

preventing parse_area_spec() from modifying start and size if it fails seems like a good idea.

Quoted 7 lines
Quoted 4 lines

However, this doesn't solve the problem, does it? parse_area_spec() only fails because the dot in 4k.bin is not valid, but if you name the file only '4k' then parse_area_spec() won't fail.
The problem is that we cannot know whether '4k' is a file or an area.

You are right. However, there is no ambiguity in the "4k.bin" and similar cases, so we can fix at least this obvious problem.

Indeed, so a patch for parse_area_spec() would be welcomed.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH 1/1 lib: parse_area_spec: don't modify *start and *size values if parse failed

---
 lib/misc.c | 46 ++++++++++++++++++++++++++++++++--------------
 1 file changed, 32 insertions(+), 14 deletions(-)
lib/misc.c +32 -14
index 62ddd6677..c7d5a0ca5 100644
@@ -79,38 +79,56 @@ EXPORT_SYMBOL(strtoul_suffix);
 int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 {
 	char *endp;
-	loff_t end;
+	loff_t end, _start, _size;
+	int ret = -1;
 
 	if (!isdigit(*str))
 		return -1;
 
-	*start = strtoull_suffix(str, &endp, 0);
+	_start = strtoull_suffix(str, &endp, 0);
 
 	str = endp;
 
 	if (!*str) {
 		/* beginning given, but no size, assume maximum size */
-		*size = ~0;
-		return 0;
+		_size = ~0;
+		ret = 0;
 	}
 
-	if (*str == '-') {
+	if (ret && *str == '-') {
 		/* beginning and end given */
-		end = strtoull_suffix(str + 1, NULL, 0);
-		if (end < *start) {
+		if (!isdigit(*(str + 1)))
+			return ret;
+
+		end = strtoull_suffix(str + 1, &endp, 0);
+		str = endp;
+		if (end < _start) {
 			printf("end < start\n");
-			return -1;
+			return ret;
 		}
-		*size = end - *start + 1;
-		return 0;
+		_size = end - _start + 1;
+		ret = 0;
 	}
 
-	if (*str == '+') {
+	if (ret && *str == '+') {
 		/* beginning and size given */
-		*size = strtoull_suffix(str + 1, NULL, 0);
-		return 0;
+		if (!isdigit(*(str + 1)))
+			return ret;
+
+		_size = strtoull_suffix(str + 1, &endp, 0);
+		str = endp;
+		ret = 0;
+	}
+
+	if (!ret && *str)
+		/* trailing symbols indicate invalid area spec */
+		ret = -1;
+
+	if (!ret) {
+		*start = _start;
+		*size = _size;
 	}
 
-	return -1;
+	return ret;
 }
 EXPORT_SYMBOL(parse_area_spec);
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

Re: [PATCH] lib: parse_area_spec: don't modify *start and *size values if parse failed

Hi Peter,

Quoted 60 lines · Peter Mamonov
---
 lib/misc.c | 46 ++++++++++++++++++++++++++++++++--------------
 1 file changed, 32 insertions(+), 14 deletions(-)
lib/misc.c +17 -13
index 62ddd6677..c7d5a0ca5 100644
@@ -79,38 +79,56 @@ EXPORT_SYMBOL(strtoul_suffix);
 int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 {
 	char *endp;
-	loff_t end;
+	loff_t end, _start, _size;
+	int ret = -1;
 
 	if (!isdigit(*str))
 		return -1;
 
-	*start = strtoull_suffix(str, &endp, 0);
+	_start = strtoull_suffix(str, &endp, 0);
 
 	str = endp;
 
 	if (!*str) {
 		/* beginning given, but no size, assume maximum size */
-		*size = ~0;
-		return 0;
+		_size = ~0;
+		ret = 0;
 	}
 
-	if (*str == '-') {
+	if (ret && *str == '-') {
 		/* beginning and end given */
-		end = strtoull_suffix(str + 1, NULL, 0);
-		if (end < *start) {
+		if (!isdigit(*(str + 1)))
+			return ret;
+
+		end = strtoull_suffix(str + 1, &endp, 0);
+		str = endp;
+		if (end < _start) {
 			printf("end < start\n");
-			return -1;
+			return ret;
 		}
-		*size = end - *start + 1;
-		return 0;
+		_size = end - _start + 1;
+		ret = 0;
 	}
 
-	if (*str == '+') {
+	if (ret && *str == '+') {
 		/* beginning and size given */
-		*size = strtoull_suffix(str + 1, NULL, 0);
-		return 0;
+		if (!isdigit(*(str + 1)))

lib/misc.c EXPORT_SYMBOL(strtoul_suffix); · line 125

Quoted 10 lines
lib/misc.c +10 -0
+			return ret;
+
+		_size = strtoull_suffix(str + 1, &endp, 0);
+		str = endp;
+		ret = 0;
+	}
+
+	if (!ret && *str)
+		/* trailing symbols indicate invalid area spec */
+		ret = -1;

Is this correct? I would assume a whitespace should be fine. We only do not get trailing whitespaces in here because current users pass in argv[] elements which are split up at whitespaces. The check would also deserve a separate patch.

lib/misc.c EXPORT_SYMBOL(strtoul_suffix); · line 132

Quoted 8 lines
lib/misc.c +5 -1
+
+	if (!ret) {
+		*start = _start;
+		*size = _size;
 	}
 
-	return -1;
+	return ret;

I find this patch unnecessarily hard to review and also the end result doesn't look optimal. Could you create a 'success:' label and jump to it when everything is fine? That would make the additional if(ret) and if(!ret) checks unnecessary.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

Re: [PATCH] lib: parse_area_spec: don't modify *start and *size values if parse failed

Hi, Sasha,

Quoted 69 lines · Sascha Hauer

Hi Peter,

Quoted 66 lines · Peter Mamonov
---
 lib/misc.c | 46 ++++++++++++++++++++++++++++++++--------------
 1 file changed, 32 insertions(+), 14 deletions(-)
lib/misc.c +23 -13
index 62ddd6677..c7d5a0ca5 100644
@@ -79,38 +79,56 @@ EXPORT_SYMBOL(strtoul_suffix);
 int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 {
 	char *endp;
-	loff_t end;
+	loff_t end, _start, _size;
+	int ret = -1;
 
 	if (!isdigit(*str))
 		return -1;
 
-	*start = strtoull_suffix(str, &endp, 0);
+	_start = strtoull_suffix(str, &endp, 0);
 
 	str = endp;
 
 	if (!*str) {
 		/* beginning given, but no size, assume maximum size */
-		*size = ~0;
-		return 0;
+		_size = ~0;
+		ret = 0;
 	}
 
-	if (*str == '-') {
+	if (ret && *str == '-') {
 		/* beginning and end given */
-		end = strtoull_suffix(str + 1, NULL, 0);
-		if (end < *start) {
+		if (!isdigit(*(str + 1)))
+			return ret;
+
+		end = strtoull_suffix(str + 1, &endp, 0);
+		str = endp;
+		if (end < _start) {
 			printf("end < start\n");
-			return -1;
+			return ret;
 		}
-		*size = end - *start + 1;
-		return 0;
+		_size = end - _start + 1;
+		ret = 0;
 	}
 
-	if (*str == '+') {
+	if (ret && *str == '+') {
 		/* beginning and size given */
-		*size = strtoull_suffix(str + 1, NULL, 0);
-		return 0;
+		if (!isdigit(*(str + 1)))
+			return ret;
+
+		_size = strtoull_suffix(str + 1, &endp, 0);
+		str = endp;
+		ret = 0;
+	}
Quoted 8 lines

lib/misc.c EXPORT_SYMBOL(strtoul_suffix); · line 125

Quoted 4 lines
lib/misc.c +4 -0
+
+	if (!ret && *str)
+		/* trailing symbols indicate invalid area spec */
+		ret = -1;

Is this correct? I would assume a whitespace should be fine. We only do not get trailing whitespaces in here because current users pass in argv[] elements which are split up at whitespaces.

Ok, whitespaces " \n\r\t" are fine too. Will fix it in the next revision.

Quoted 2 lines

The check would
also deserve a separate patch.

My proposal is to fix parse_area_spec so it can distinguish a valid memory area specification from the following sample file names:

	4k.bin
	4k-8k.txt
	4096+1k_of_random_bytes

Without this final check parse_area_spec would return 0 for the last two samples, which are not valid area specifications.

Quoted 7 lines
Quoted 7 lines
lib/misc.c +4 -0
+
+	if (!ret) {
+		*start = _start;
+		*size = _size;
 	}
 
Quoted 7 lines

lib/misc.c EXPORT_SYMBOL(strtoul_suffix); · line 132

Quoted 2 lines
lib/misc.c +1 -1
-	return -1;
+	return ret;

I find this patch unnecessarily hard to review and also the end result doesn't look optimal. Could you create a 'success:' label and jump to it when everything is fine? That would make the additional if(ret) and if(!ret) checks unnecessary.

Sounds good, will fix it as well.

Regards,
Peter

Quoted 8 lines

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#8 lore raw

PATCH v2 1/3 lib: parse_area_spec: don't modify *start value if parse failed

In reply to Sascha Hauer
---
 lib/misc.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
lib/misc.c +9 -5
index 62ddd6677..1767043d1 100644
@@ -79,19 +79,19 @@ EXPORT_SYMBOL(strtoul_suffix);
 int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 {
 	char *endp;
-	loff_t end;
+	loff_t end, _start;
 
 	if (!isdigit(*str))
 		return -1;
 
-	*start = strtoull_suffix(str, &endp, 0);
+	_start = strtoull_suffix(str, &endp, 0);
 
 	str = endp;
 
 	if (!*str) {
 		/* beginning given, but no size, assume maximum size */
 		*size = ~0;
-		return 0;
+		goto success;
 	}
 
 	if (*str == '-') {
@@ -102,15 +102,19 @@ int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 			return -1;
 		}
 		*size = end - *start + 1;
-		return 0;
+		goto success;
 	}
 
 	if (*str == '+') {
 		/* beginning and size given */
 		*size = strtoull_suffix(str + 1, NULL, 0);
-		return 0;
+		goto success;
 	}
 
 	return -1;
+
+success:
+	*start = _start;
+	return 0;
 }
 EXPORT_SYMBOL(parse_area_spec);
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

PATCH v2 2/3 lib: parse_area_spec: part of the area spec after -/+ should start with a digit

---
 lib/misc.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/misc.c +6 -0
index 1767043d1..fc2c45aa4 100644
@@ -96,6 +96,9 @@ int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 
 	if (*str == '-') {
 		/* beginning and end given */
+		if (!isdigit(*(str + 1)))
+			return -1;
+
 		end = strtoull_suffix(str + 1, NULL, 0);
 		if (end < *start) {
 			printf("end < start\n");
@@ -107,6 +110,9 @@ int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 
 	if (*str == '+') {
 		/* beginning and size given */
+		if (!isdigit(*(str + 1)))
+			return -1;
+
 		*size = strtoull_suffix(str + 1, NULL, 0);
 		goto success;
 	}
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw

PATCH v2 3/3 lib: parse_area_spec: no extra symbols after area spec are allowed except for spaces

In reply to Peter Mamonov
---
 lib/misc.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
lib/misc.c +10 -5
index fc2c45aa4..4b62f8771 100644
@@ -79,7 +79,7 @@ EXPORT_SYMBOL(strtoul_suffix);
 int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 {
 	char *endp;
-	loff_t end, _start;
+	loff_t end, _start, _size;
 
 	if (!isdigit(*str))
 		return -1;
@@ -90,7 +90,7 @@ int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 
 	if (!*str) {
 		/* beginning given, but no size, assume maximum size */
-		*size = ~0;
+		_size = ~0;
 		goto success;
 	}
 
@@ -99,12 +99,13 @@ int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 		if (!isdigit(*(str + 1)))
 			return -1;
 
-		end = strtoull_suffix(str + 1, NULL, 0);
+		end = strtoull_suffix(str + 1, &endp, 0);
+		str = endp;
 		if (end < *start) {
 			printf("end < start\n");
 			return -1;
 		}
-		*size = end - *start + 1;
+		_size = end - *start + 1;
 		goto success;
 	}
 
@@ -113,14 +114,18 @@ int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 		if (!isdigit(*(str + 1)))
 			return -1;
 
-		*size = strtoull_suffix(str + 1, NULL, 0);
+		_size = strtoull_suffix(str + 1, &endp, 0);
+		str = endp;
 		goto success;
 	}
 
 	return -1;
 
 success:
+	if (*str && !isspace(*str))
+		return -1;
 	*start = _start;
+	*size = _size;
 	return 0;
 }
 EXPORT_SYMBOL(parse_area_spec);
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#11 lore raw

Re: [PATCH v2 1/3] lib: parse_area_spec: don't modify *start value if parse failed

In reply to Peter Mamonov
Quoted 33 lines · Peter Mamonov
---
 lib/misc.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
lib/misc.c +3 -3
index 62ddd6677..1767043d1 100644
@@ -79,19 +79,19 @@ EXPORT_SYMBOL(strtoul_suffix);
 int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 {
 	char *endp;
-	loff_t end;
+	loff_t end, _start;
 
 	if (!isdigit(*str))
 		return -1;
 
-	*start = strtoull_suffix(str, &endp, 0);
+	_start = strtoull_suffix(str, &endp, 0);
 
 	str = endp;
 
 	if (!*str) {
 		/* beginning given, but no size, assume maximum size */
 		*size = ~0;
-		return 0;
+		goto success;
 	}
 
 	if (*str == '-') {

lib/misc.c int parse_area_spec(const char *str, loff_t *start, loff_t *size) · line 104

Quoted 3 lines
lib/misc.c +0 -0
@@ -102,15 +102,19 @@ int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 			return -1;
 		}
 		*size = end - *start + 1;

Applied with two little changes: It must be _start above and in another case not visible in the patch. *start is not yet initialized.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#12 lore raw

Re: [PATCH v2 1/3] lib: parse_area_spec: don't modify *start value if parse failed

Quoted 32 lines · Sascha Hauer
Quoted 31 lines · Peter Mamonov
---
 lib/misc.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
lib/misc.c +3 -3
index 62ddd6677..1767043d1 100644
@@ -79,19 +79,19 @@ EXPORT_SYMBOL(strtoul_suffix);
 int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 {
 	char *endp;
-	loff_t end;
+	loff_t end, _start;
 
 	if (!isdigit(*str))
 		return -1;
 
-	*start = strtoull_suffix(str, &endp, 0);
+	_start = strtoull_suffix(str, &endp, 0);
 
 	str = endp;
 
 	if (!*str) {
 		/* beginning given, but no size, assume maximum size */
 		*size = ~0;
-		return 0;
+		goto success;
 	}
 
Quoted 8 lines

lib/misc.c int parse_area_spec(const char *str, loff_t *start, loff_t *size) · line 104

Quoted 5 lines
lib/misc.c +0 -0
 	if (*str == '-') {
@@ -102,15 +102,19 @@ int parse_area_spec(const char *str, loff_t *start, loff_t *size)
 			return -1;
 		}
 		*size = end - *start + 1;

Applied with two little changes: It must be _start above and in another case not visible in the patch. *start is not yet initialized.

Thanks for correction. Actually these changes were present in the original patch, but I've missed them while rearranging it.

Regards,
Peter

Quoted 9 lines

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox