[4/7] btrfs-progs: check for numerical in version_to_code()
diff mbox

Message ID 1448453300-8449-5-git-send-email-anand.jain@oracle.com
State New
Headers show

Commit Message

Anand Jain Nov. 25, 2015, 12:08 p.m. UTC
As the version is now being passed by user it should be checked
if its numerical. We didn't need this before as version wasn't
passed by used. So this is not a bug fix.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 utils.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Patch
diff mbox

diff --git a/utils.c b/utils.c
index 0e66e2b..216efa6 100644
--- a/utils.c
+++ b/utils.c
@@ -3119,14 +3119,18 @@  static int version_to_code(char *v)
 
 	for (b[i] = strtok_r(v, ".", &save_b);
 		b[i] != NULL;
-		b[i] = strtok_r(NULL, ".", &save_b))
+		b[i] = strtok_r(NULL, ".", &save_b)) {
+		if (!is_numerical(b[i]))
+			return -EINVAL;
 		i++;
+	}
 
+	if (b[1] == NULL)
+		return KERNEL_VERSION(atoi(b[0]), 0, 0);
 	if (b[2] == NULL)
 		return KERNEL_VERSION(atoi(b[0]), atoi(b[1]), 0);
-	else
-		return KERNEL_VERSION(atoi(b[0]), atoi(b[1]), atoi(b[2]));
 
+	return KERNEL_VERSION(atoi(b[0]), atoi(b[1]), atoi(b[2]));
 }
 
 static int get_kernel_code()