Message ID | 20230803162326.302824-1-cgzones@googlemail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 3459dfd92e46 |
Delegated to: | Petr Lautrbach |
Headers | show |
Series | [1/4] libselinux/utils: update selabel_partial_match | expand |
On Thu, Aug 3, 2023 at 12:37 PM 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> For this four patch series: 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 >
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(-)