All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Mamonov <pmamonov@gmail.com>
To: s.hauer@pengutronix.de
Cc: barebox@lists.infradead.org, Peter Mamonov <pmamonov@gmail.com>
Subject: [PATCH v2 3/3] lib: parse_area_spec: no extra symbols after area spec are allowed except for spaces
Date: Mon, 15 Jan 2018 14:32:33 +0300	[thread overview]
Message-ID: <20180115113233.30610-3-pmamonov@gmail.com> (raw)
In-Reply-To: <20180115113233.30610-1-pmamonov@gmail.com>

Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
---
 lib/misc.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/lib/misc.c b/lib/misc.c
index fc2c45aa4..4b62f8771 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -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);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2018-01-15 11:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-20 10:48 command: hashsum: md5sum reports wrong sum for the file named 4k.bin Peter Mamonov
2017-12-21 10:48 ` Peter Mamonov
2018-01-05 11:44   ` Sascha Hauer
2018-01-05 18:17     ` Peter Mamonov
2018-01-09 11:10       ` Sascha Hauer
2018-01-09 14:21         ` [PATCH] lib: parse_area_spec: don't modify *start and *size values if parse failed Peter Mamonov
2018-01-11  8:15           ` Sascha Hauer
2018-01-11 17:28             ` Peter Mamonov
2018-01-15 11:32             ` [PATCH v2 1/3] lib: parse_area_spec: don't modify *start value " Peter Mamonov
2018-01-15 11:32               ` [PATCH v2 2/3] lib: parse_area_spec: part of the area spec after -/+ should start with a digit Peter Mamonov
2018-01-15 11:32               ` Peter Mamonov [this message]
2018-01-17  8:11               ` [PATCH v2 1/3] lib: parse_area_spec: don't modify *start value if parse failed Sascha Hauer
2018-01-17  9:31                 ` Peter Mamonov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180115113233.30610-3-pmamonov@gmail.com \
    --to=pmamonov@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.