Message ID | 20230814132025.45364-2-cgzones@googlemail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 3459dfd92e46 |
Delegated to: | Petr Lautrbach |
Headers | show |
Series | libselinux: rework selabel_file(5) database | expand |
On Mon, Aug 14, 2023 at 9:41 AM Christian Göttsche <cgzones@googlemail.com> wrote: > > Print usage information and exit if required path option is not given > or superfluous arguments are given. > > Constify read-only variables assigned command line arguments. > > Simplify bool evaluation. > > Signed-off-by: Christian Göttsche <cgzones@googlemail.com> Acked-by: James Carter <jwcart2@gmail.com> > --- > libselinux/utils/selabel_partial_match.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/libselinux/utils/selabel_partial_match.c b/libselinux/utils/selabel_partial_match.c > index 7bbd5777..0df2627a 100644 > --- a/libselinux/utils/selabel_partial_match.c > +++ b/libselinux/utils/selabel_partial_match.c > @@ -28,7 +28,7 @@ int main(int argc, char **argv) > { > int opt; > bool partial_match; > - char *validate = NULL, *path = NULL, *file = NULL; > + const char *validate = NULL, *path = NULL, *file = NULL; > > struct selabel_handle *hnd; > struct selinux_opt selabel_option[] = { > @@ -55,6 +55,9 @@ int main(int argc, char **argv) > } > } > > + if (!path || optind != argc) > + usage(argv[0]); > + > selabel_option[0].value = file; > selabel_option[1].value = validate; > > @@ -69,7 +72,7 @@ int main(int argc, char **argv) > partial_match = selabel_partial_match(hnd, path); > > printf("Match or Partial match: %s\n", > - partial_match == 1 ? "TRUE" : "FALSE"); > + partial_match ? "TRUE" : "FALSE"); > > selabel_close(hnd); > return partial_match; > -- > 2.40.1 >
On Mon, Oct 2, 2023 at 1:13 PM James Carter <jwcart2@gmail.com> wrote: > > On Mon, Aug 14, 2023 at 9:41 AM Christian Göttsche > <cgzones@googlemail.com> wrote: > > > > Print usage information and exit if required path option is not given > > or superfluous arguments are given. > > > > Constify read-only variables assigned command line arguments. > > > > Simplify bool evaluation. > > > > Signed-off-by: Christian Göttsche <cgzones@googlemail.com> > > Acked-by: James Carter <jwcart2@gmail.com> > Merged. Thanks, Jim > > --- > > libselinux/utils/selabel_partial_match.c | 7 +++++-- > > 1 file changed, 5 insertions(+), 2 deletions(-) > > > > diff --git a/libselinux/utils/selabel_partial_match.c b/libselinux/utils/selabel_partial_match.c > > index 7bbd5777..0df2627a 100644 > > --- a/libselinux/utils/selabel_partial_match.c > > +++ b/libselinux/utils/selabel_partial_match.c > > @@ -28,7 +28,7 @@ int main(int argc, char **argv) > > { > > int opt; > > bool partial_match; > > - char *validate = NULL, *path = NULL, *file = NULL; > > + const char *validate = NULL, *path = NULL, *file = NULL; > > > > struct selabel_handle *hnd; > > struct selinux_opt selabel_option[] = { > > @@ -55,6 +55,9 @@ int main(int argc, char **argv) > > } > > } > > > > + if (!path || optind != argc) > > + usage(argv[0]); > > + > > selabel_option[0].value = file; > > selabel_option[1].value = validate; > > > > @@ -69,7 +72,7 @@ int main(int argc, char **argv) > > partial_match = selabel_partial_match(hnd, path); > > > > printf("Match or Partial match: %s\n", > > - partial_match == 1 ? "TRUE" : "FALSE"); > > + partial_match ? "TRUE" : "FALSE"); > > > > selabel_close(hnd); > > return partial_match; > > -- > > 2.40.1 > >
diff --git a/libselinux/utils/selabel_partial_match.c b/libselinux/utils/selabel_partial_match.c index 7bbd5777..0df2627a 100644 --- a/libselinux/utils/selabel_partial_match.c +++ b/libselinux/utils/selabel_partial_match.c @@ -28,7 +28,7 @@ int main(int argc, char **argv) { int opt; bool partial_match; - char *validate = NULL, *path = NULL, *file = NULL; + const char *validate = NULL, *path = NULL, *file = NULL; struct selabel_handle *hnd; struct selinux_opt selabel_option[] = { @@ -55,6 +55,9 @@ int main(int argc, char **argv) } } + if (!path || optind != argc) + usage(argv[0]); + selabel_option[0].value = file; selabel_option[1].value = validate; @@ -69,7 +72,7 @@ int main(int argc, char **argv) partial_match = selabel_partial_match(hnd, path); printf("Match or Partial match: %s\n", - partial_match == 1 ? "TRUE" : "FALSE"); + partial_match ? "TRUE" : "FALSE"); selabel_close(hnd); return partial_match;
Print usage information and exit if required path option is not given or superfluous arguments are given. Constify read-only variables assigned command line arguments. Simplify bool evaluation. Signed-off-by: Christian Göttsche <cgzones@googlemail.com> --- libselinux/utils/selabel_partial_match.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)