From df766f09cb067e52b93adf33e7066cce6768f167 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Sat, 30 Jun 2018 12:48:35 +0200 Subject: [PATCH] containerfs: check for invalid mappings Signed-off-by: Giuseppe Scrivano --- main.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index b8d75f2..d34f1ff 100644 --- a/main.c +++ b/main.c @@ -152,7 +152,7 @@ lo_data (fuse_req_t req) static struct lo_mapping * read_mappings (const char *str) { - char *buf = NULL, *saveptr = NULL, *it; + char *buf = NULL, *saveptr = NULL, *it, *endptr; struct lo_mapping *tmp, *ret = NULL; unsigned int a, b, c; int state = 0; @@ -165,17 +165,23 @@ read_mappings (const char *str) switch (state) { case 0: - a = strtol (it, NULL, 10); + a = strtol (it, &endptr, 10); + if (*endptr != 0) + error (EXIT_FAILURE, 0, "invalid mapping specified: %s", str); state++; break; case 1: - b = strtol (it, NULL, 10); + b = strtol (it, &endptr, 10); + if (*endptr != 0) + error (EXIT_FAILURE, 0, "invalid mapping specified: %s", str); state++; break; case 2: - c = strtol (it, NULL, 10); + c = strtol (it, &endptr, 10); + if (*endptr != 0) + error (EXIT_FAILURE, 0, "invalid mapping specified: %s", str); state = 0; tmp = malloc (sizeof (*tmp)); @@ -190,6 +196,9 @@ read_mappings (const char *str) } } + if (state != 0) + error (EXIT_FAILURE, 0, "invalid mapping specified: %s", str); + return ret; }