From: Goffredo Baroncelli <kreijack@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Stefan Behrens <sbehrens@giantdisaster.de>,
Wang Sheng-Hui <shhuiw@gmail.com>,
Goffredo Baroncelli <kreijack@inwind.it>
Subject: [PATCH 3/5] parse_size(): check for invalid suffix
Date: Mon, 22 Oct 2012 22:17:46 +0200 [thread overview]
Message-ID: <1350937068-10080-4-git-send-email-kreijack@inwind.com> (raw)
In-Reply-To: <1350937068-10080-1-git-send-email-kreijack@inwind.com>
From: Goffredo Baroncelli <kreijack@inwind.it>
Check that the suffix for the parse_size() input is of only
one character.
---
utils.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/utils.c b/utils.c
index 732c782..de75309 100644
--- a/utils.c
+++ b/utils.c
@@ -1226,6 +1226,11 @@ u64 parse_size(char *s)
char c;
u64 mult = 1;
+ if( len <= 0 ){
+ fprintf(stderr, "ERROR: size value is empty\n");
+ exit(50);
+ }
+
if (!isdigit(s[len - 1])) {
c = tolower(s[len - 1]);
switch (c) {
@@ -1242,6 +1247,13 @@ u64 parse_size(char *s)
exit(1);
}
s[len - 1] = '\0';
+ len--;
+ }
+ if( len > 0 && !isdigit(s[len - 1])) {
+ fprintf(stderr, "ERROR: Illegal size value contains "
+ "non-digit character %c in wrong position\n",
+ s[len-1]);
+ exit(51);
}
return strtoull(s, NULL, 0) * mult;
}
--
1.7.10.4
next prev parent reply other threads:[~2012-10-22 20:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-22 20:17 [PATCH][BTRFS-PROGS] Update to parse_size() Goffredo Baroncelli
2012-10-22 20:17 ` [PATCH 1/5] Move parse_size() to utils.[hc] Goffredo Baroncelli
2012-10-22 20:17 ` [PATCH 2/5] parse_size(): replace atoll() with strtoull() Goffredo Baroncelli
2012-10-22 20:17 ` Goffredo Baroncelli [this message]
2012-10-22 20:17 ` [PATCH 4/5] parse_size(): add new suffixes Goffredo Baroncelli
2012-10-22 20:17 ` [PATCH 5/5] Update the man page with the new prefixes Goffredo Baroncelli
-- strict thread matches above, loose matches on Subject: below --
2012-10-23 17:51 [PATCH][BTRFS-PROGS][V2] Update to parse_size() Goffredo Baroncelli
2012-10-23 17:51 ` [PATCH 3/5] parse_size(): check for invalid suffix Goffredo Baroncelli
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=1350937068-10080-4-git-send-email-kreijack@inwind.com \
--to=kreijack@gmail.com \
--cc=kreijack@inwind.it \
--cc=linux-btrfs@vger.kernel.org \
--cc=sbehrens@giantdisaster.de \
--cc=shhuiw@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).