Skip to content

Commit

Permalink
confile: return negative errno everywhere
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Oct 14, 2021
1 parent 61dd752 commit 251bd80
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
10 changes: 5 additions & 5 deletions src/lxc/af_unix.c
Expand Up @@ -480,17 +480,17 @@ int lxc_unix_sockaddr(struct sockaddr_un *ret, const char *path)

len = strlen(path);
if (len == 0)
return ret_set_errno(-1, EINVAL);
return ret_errno(EINVAL);
if (path[0] != '/' && path[0] != '@')
return ret_set_errno(-1, EINVAL);
return ret_errno(EINVAL);
if (path[1] == '\0')
return ret_set_errno(-1, EINVAL);
return ret_errno(EINVAL);

if (len + 1 > sizeof(ret->sun_path))
return ret_set_errno(-1, EINVAL);
return ret_errno(EINVAL);

*ret = (struct sockaddr_un){
.sun_family = AF_UNIX,
.sun_family = AF_UNIX,
};

if (path[0] == '@') {
Expand Down
42 changes: 19 additions & 23 deletions src/lxc/confile.c
Expand Up @@ -375,10 +375,8 @@ static struct lxc_config_net_t *lxc_get_config_net(const char *key)
static int set_config_net(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data)
{
if (!lxc_config_value_empty(value)) {
ERROR("lxc.net must not have a value");
return -1;
}
if (!lxc_config_value_empty(value))
return syserror_set(-EINVAL, "lxc.net must not have a value");

return clr_config_net(key, lxc_conf, data);
}
Expand Down Expand Up @@ -995,7 +993,7 @@ static int set_config_net_veth_ipv6_route(const char *key, const char *value,

valdup = strdup(value);
if (!valdup)
return -1;
return ret_errno(ENOMEM);

slash = strchr(valdup, '/');
if (!slash)
Expand Down Expand Up @@ -1077,15 +1075,14 @@ static int set_config_seccomp_allow_nesting(const char *key, const char *value,
return clr_config_seccomp_allow_nesting(key, lxc_conf, NULL);

if (lxc_safe_uint(value, &lxc_conf->seccomp.allow_nesting) < 0)
return -1;
return -errno;

if (lxc_conf->seccomp.allow_nesting > 1)
return ret_set_errno(-1, EINVAL);
return ret_errno(EINVAL);

return 0;
#else
errno = ENOSYS;
return -1;
return ret_errno(ENOSYS);
#endif
}

Expand All @@ -1095,7 +1092,7 @@ static int set_config_seccomp_notify_cookie(const char *key, const char *value,
#ifdef HAVE_SECCOMP_NOTIFY
return set_config_string_item(&lxc_conf->seccomp.notifier.cookie, value);
#else
return ret_set_errno(-1, ENOSYS);
return ret_errno(ENOSYS);
#endif
}

Expand All @@ -1109,15 +1106,15 @@ static int set_config_seccomp_notify_proxy(const char *key, const char *value,
return clr_config_seccomp_notify_proxy(key, lxc_conf, NULL);

if (!strnequal(value, "unix:", 5))
return ret_set_errno(-1, EINVAL);
return ret_errno(EINVAL);

offset = value + 5;
if (lxc_unix_sockaddr(&lxc_conf->seccomp.notifier.proxy_addr, offset) < 0)
return -1;
return -errno;

return 0;
#else
return ret_set_errno(-1, ENOSYS);
return ret_errno(ENOSYS);
#endif
}

Expand All @@ -1127,7 +1124,7 @@ static int set_config_seccomp_profile(const char *key, const char *value,
#ifdef HAVE_SECCOMP
return set_config_path_item(&lxc_conf->seccomp.seccomp, value);
#else
return ret_set_errno(-1, ENOSYS);
return ret_errno(ENOSYS);
#endif
}

Expand Down Expand Up @@ -1160,7 +1157,7 @@ static int set_config_init_uid(const char *key, const char *value,
}

if (lxc_safe_uint(value, &init_uid) < 0)
return -1;
return -errno;

lxc_conf->init_uid = init_uid;

Expand All @@ -1178,7 +1175,7 @@ static int set_config_init_gid(const char *key, const char *value,
}

if (lxc_safe_uint(value, &init_gid) < 0)
return -1;
return -errno;

lxc_conf->init_gid = init_gid;

Expand Down Expand Up @@ -1293,11 +1290,10 @@ static int set_config_hooks_version(const char *key, const char *value,

ret = lxc_safe_uint(value, &tmp);
if (ret < 0)
return -1;
return -errno;

if (tmp > 1)
return log_error_errno(-EINVAL,
EINVAL, "Invalid hook version specified. Currently only 0 (legacy) and 1 are supported");
return syserror_set(-EINVAL, "Invalid hook version specified. Currently only 0 (legacy) and 1 are supported");

lxc_conf->hooks_version = tmp;

Expand Down Expand Up @@ -2008,11 +2004,11 @@ static int set_config_sysctl(const char *key, const char *value,
return clr_config_sysctl(key, lxc_conf, NULL);

if (!strnequal(key, "lxc.sysctl.", STRLITERALLEN("lxc.sysctl.")))
return -1;
return ret_errno(EINVAL);

key += STRLITERALLEN("lxc.sysctl.");
if (is_empty_string(key))
return ret_errno(-EINVAL);
return ret_errno(EINVAL);

/* find existing list element */
lxc_list_for_each(iter, &lxc_conf->sysctls) {
Expand Down Expand Up @@ -2066,7 +2062,7 @@ static int set_config_proc(const char *key, const char *value,
return clr_config_proc(key, lxc_conf, NULL);

if (!strnequal(key, "lxc.proc.", STRLITERALLEN("lxc.proc.")))
return -1;
return ret_errno(EINVAL);

subkey = key + STRLITERALLEN("lxc.proc.");
if (*subkey == '\0')
Expand Down Expand Up @@ -4150,7 +4146,7 @@ static int get_config_start(const char *key, char *retv, int inlen,
else if (strequal(key + 10, "order"))
return lxc_get_conf_int(c, retv, inlen, c->start_order);

return -1;
return ret_errno(EINVAL);
}

static int get_config_log_syslog(const char *key, char *retv, int inlen,
Expand Down

0 comments on commit 251bd80

Please sign in to comment.