Commit dd871fa0 by Christian Brauner Committed by GitHub

Merge pull request #1720 from hallyn/2017-07-29/cg

Fix some bugs in #1719
parents 1135b35b 2c2d6c49
...@@ -1904,11 +1904,10 @@ static int cgfsng_set(const char *filename, const char *value, const char *name, ...@@ -1904,11 +1904,10 @@ static int cgfsng_set(const char *filename, const char *value, const char *name,
*/ */
static int convert_devpath(const char *invalue, char *dest) static int convert_devpath(const char *invalue, char *dest)
{ {
char *p, *path, *mode, type = 0; char *p, *path, *mode, type;
struct stat sb; struct stat sb;
unsigned long minor, major; unsigned long minor, major;
int n_parts, ret; int n_parts, ret = -EINVAL;
dev_t dev;
path = must_copy_string(invalue); path = must_copy_string(invalue);
...@@ -1918,25 +1917,27 @@ static int convert_devpath(const char *invalue, char *dest) ...@@ -1918,25 +1917,27 @@ static int convert_devpath(const char *invalue, char *dest)
* is not legal, we could check for that if we cared to * is not legal, we could check for that if we cared to
*/ */
for (n_parts = 1, p = path; *p && n_parts < 3; p++) { for (n_parts = 1, p = path; *p && n_parts < 3; p++) {
if (*p == ' ') { if (*p != ' ')
continue;
*p = '\0'; *p = '\0';
mode = p + 1; if (n_parts != 1)
break;
p++;
n_parts++; n_parts++;
while (*p == ' ') while (*p == ' ')
p++; p++;
} mode = p;
} if (*p == '\0')
if (n_parts == 1) {
ret = -EINVAL;
goto out; goto out;
} }
if (n_parts == 1)
goto out;
ret = stat(path, &sb); ret = stat(path, &sb);
if (ret < 0) if (ret < 0)
goto out; goto out;
dev = sb.st_rdev;
mode_t m = sb.st_mode & S_IFMT; mode_t m = sb.st_mode & S_IFMT;
switch (m) { switch (m) {
case S_IFBLK: case S_IFBLK:
...@@ -1945,16 +1946,15 @@ static int convert_devpath(const char *invalue, char *dest) ...@@ -1945,16 +1946,15 @@ static int convert_devpath(const char *invalue, char *dest)
case S_IFCHR: case S_IFCHR:
type = 'c'; type = 'c';
break; break;
} default:
if (type == 0) {
ERROR("Unsupported device type %i for %s", m, path); ERROR("Unsupported device type %i for %s", m, path);
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
major = MAJOR(dev), minor = MINOR(dev);
ret = snprintf(dest, 50, major = MAJOR(sb.st_rdev);
"%c %lu:%lu %s", type, major, minor, mode); minor = MINOR(sb.st_rdev);
ret = snprintf(dest, 50, "%c %lu:%lu %s", type, major, minor, mode);
if (ret < 0 || ret >= 50) { if (ret < 0 || ret >= 50) {
ERROR("Error on configuration value \"%c %lu:%lu %s\" (max 50 chars)", ERROR("Error on configuration value \"%c %lu:%lu %s\" (max 50 chars)",
type, major, minor, mode); type, major, minor, mode);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment