libselinux: fail selabel_open(3) on invalid option

Return an error on invalid selabel_open(3) options, e.g. an option for
a different backend was used.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
Christian Göttsche 2023-12-19 17:09:28 +01:00 committed by James Carter
parent 7f925776d9
commit 65c8fd457b
5 changed files with 36 additions and 0 deletions

View File

@ -157,6 +157,13 @@ static int init(struct selabel_handle *rec, const struct selinux_opt *opts,
case SELABEL_OPT_PATH:
path = opts[n].value;
break;
case SELABEL_OPT_UNUSED:
case SELABEL_OPT_VALIDATE:
case SELABEL_OPT_DIGEST:
break;
default:
errno = EINVAL;
return -1;
}
if (!path)

View File

@ -268,6 +268,14 @@ db_init(const struct selinux_opt *opts, unsigned nopts,
case SELABEL_OPT_PATH:
path = opts[nopts].value;
break;
case SELABEL_OPT_UNUSED:
case SELABEL_OPT_VALIDATE:
case SELABEL_OPT_DIGEST:
break;
default:
free(catalog);
errno = EINVAL;
return NULL;
}
}

View File

@ -812,6 +812,13 @@ static int init(struct selabel_handle *rec, const struct selinux_opt *opts,
case SELABEL_OPT_BASEONLY:
baseonly = !!opts[n].value;
break;
case SELABEL_OPT_UNUSED:
case SELABEL_OPT_VALIDATE:
case SELABEL_OPT_DIGEST:
break;
default:
errno = EINVAL;
return -1;
}
#if !defined(BUILD_HOST) && !defined(ANDROID)

View File

@ -85,6 +85,13 @@ static int init(struct selabel_handle *rec, const struct selinux_opt *opts,
case SELABEL_OPT_PATH:
path = opts[n].value;
break;
case SELABEL_OPT_UNUSED:
case SELABEL_OPT_VALIDATE:
case SELABEL_OPT_DIGEST:
break;
default:
errno = EINVAL;
return -1;
}
/* Open the specification file. */

View File

@ -112,6 +112,13 @@ static int init(struct selabel_handle *rec, const struct selinux_opt *opts,
case SELABEL_OPT_PATH:
path = opts[n].value;
break;
case SELABEL_OPT_UNUSED:
case SELABEL_OPT_VALIDATE:
case SELABEL_OPT_DIGEST:
break;
default:
errno = EINVAL;
return -1;
}
/* Open the specification file. */