[PATCH 3/5] parse_size(): check for invalid suffix

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Goffredo Baroncelli <kreijack@xxxxxxxxx>

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

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux