containerfs: check for invalid mappings

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2018-06-30 12:48:35 +02:00
parent f131a755fa
commit df766f09cb
No known key found for this signature in database
GPG Key ID: E4730F97F60286ED

17
main.c
View File

@ -152,7 +152,7 @@ lo_data (fuse_req_t req)
static struct lo_mapping * static struct lo_mapping *
read_mappings (const char *str) read_mappings (const char *str)
{ {
char *buf = NULL, *saveptr = NULL, *it; char *buf = NULL, *saveptr = NULL, *it, *endptr;
struct lo_mapping *tmp, *ret = NULL; struct lo_mapping *tmp, *ret = NULL;
unsigned int a, b, c; unsigned int a, b, c;
int state = 0; int state = 0;
@ -165,17 +165,23 @@ read_mappings (const char *str)
switch (state) switch (state)
{ {
case 0: 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++; state++;
break; break;
case 1: 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++; state++;
break; break;
case 2: 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; state = 0;
tmp = malloc (sizeof (*tmp)); 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; return ret;
} }