libselinux: make context_*_set() return -1 when an error occurs

In libselinux, most functions set errno and return -1 when an error
occurs. But some functions return 1 instead, such as context_type_set(),
context_role_set(), etc. This increases the difficulty of writing Python
bindings of these functions without much benefit.

Return -1 instead (errno was already set).

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
This commit is contained in:
Nicolas Iooss 2020-04-12 10:10:01 +02:00 committed by William Roberts
parent 164f437b19
commit 091549b2d0

View File

@ -151,14 +151,14 @@ static int set_comp(context_private_t * n, int idx, const char *str)
if (str) {
t = (char *)malloc(strlen(str) + 1);
if (!t) {
return 1;
return -1;
}
for (p = str; *p; p++) {
if (*p == '\t' || *p == '\n' || *p == '\r' ||
((*p == ':' || *p == ' ') && idx != COMP_RANGE)) {
free(t);
errno = EINVAL;
return 1;
return -1;
}
}
strcpy(t, str);