Re: [RFC PATCH v2 07/27] libselinux: constify selabel_cmp(3) parameters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Oct 2, 2023 at 2:11 PM James Carter <jwcart2@xxxxxxxxx> wrote:
>
> On Mon, Aug 14, 2023 at 9:42 AM Christian Göttsche
> <cgzones@xxxxxxxxxxxxxx> wrote:
> >
> > Comparing two selabel handles should (and currently does) not modify
> > them.
> >
> > Signed-off-by: Christian Göttsche <cgzones@xxxxxxxxxxxxxx>
>
> Acked-by: James Carter <jwcart2@xxxxxxxxx>
>
Merged.
Thanks,
Jim

> > ---
> >  libselinux/include/selinux/label.h |  4 ++--
> >  libselinux/src/label.c             |  4 ++--
> >  libselinux/src/label_file.c        | 22 +++++++++++-----------
> >  libselinux/src/label_internal.h    |  4 ++--
> >  4 files changed, 17 insertions(+), 17 deletions(-)
> >
> > diff --git a/libselinux/include/selinux/label.h b/libselinux/include/selinux/label.h
> > index e8983606..ce189a3a 100644
> > --- a/libselinux/include/selinux/label.h
> > +++ b/libselinux/include/selinux/label.h
> > @@ -153,8 +153,8 @@ enum selabel_cmp_result {
> >   * if @h1 is identical to @h2, %SELABEL_SUPERSET if @h1 is a superset
> >   * of @h2, and %SELABEL_INCOMPARABLE if @h1 and @h2 are incomparable.
> >   */
> > -extern enum selabel_cmp_result selabel_cmp(struct selabel_handle *h1,
> > -                                          struct selabel_handle *h2);
> > +extern enum selabel_cmp_result selabel_cmp(const struct selabel_handle *h1,
> > +                                          const struct selabel_handle *h2);
> >
> >  /**
> >   * selabel_stats - log labeling operation statistics.
> > diff --git a/libselinux/src/label.c b/libselinux/src/label.c
> > index a2efa99c..c0f586a2 100644
> > --- a/libselinux/src/label.c
> > +++ b/libselinux/src/label.c
> > @@ -333,8 +333,8 @@ int selabel_lookup_best_match_raw(struct selabel_handle *rec, char **con,
> >         return *con ? 0 : -1;
> >  }
> >
> > -enum selabel_cmp_result selabel_cmp(struct selabel_handle *h1,
> > -                                   struct selabel_handle *h2)
> > +enum selabel_cmp_result selabel_cmp(const struct selabel_handle *h1,
> > +                                   const struct selabel_handle *h2)
> >  {
> >         if (!h1->func_cmp || h1->func_cmp != h2->func_cmp)
> >                 return SELABEL_INCOMPARABLE;
> > diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
> > index 461abc61..5ac23e1f 100644
> > --- a/libselinux/src/label_file.c
> > +++ b/libselinux/src/label_file.c
> > @@ -1237,7 +1237,7 @@ out:
> >         return lr;
> >  }
> >
> > -static enum selabel_cmp_result incomp(struct spec *spec1, struct spec *spec2, const char *reason, int i, int j)
> > +static enum selabel_cmp_result incomp(const struct spec *spec1, const struct spec *spec2, const char *reason, int i, int j)
> >  {
> >         selinux_log(SELINUX_INFO,
> >                     "selabel_cmp: mismatched %s on entry %d: (%s, %x, %s) vs entry %d: (%s, %x, %s)\n",
> > @@ -1247,21 +1247,21 @@ static enum selabel_cmp_result incomp(struct spec *spec1, struct spec *spec2, co
> >         return SELABEL_INCOMPARABLE;
> >  }
> >
> > -static enum selabel_cmp_result cmp(struct selabel_handle *h1,
> > -                                  struct selabel_handle *h2)
> > +static enum selabel_cmp_result cmp(const struct selabel_handle *h1,
> > +                                  const struct selabel_handle *h2)
> >  {
> > -       struct saved_data *data1 = (struct saved_data *)h1->data;
> > -       struct saved_data *data2 = (struct saved_data *)h2->data;
> > +       const struct saved_data *data1 = (const struct saved_data *)h1->data;
> > +       const struct saved_data *data2 = (const struct saved_data *)h2->data;
> >         unsigned int i, nspec1 = data1->nspec, j, nspec2 = data2->nspec;
> > -       struct spec *spec_arr1 = data1->spec_arr, *spec_arr2 = data2->spec_arr;
> > -       struct stem *stem_arr1 = data1->stem_arr, *stem_arr2 = data2->stem_arr;
> > +       const struct spec *spec_arr1 = data1->spec_arr, *spec_arr2 = data2->spec_arr;
> > +       const struct stem *stem_arr1 = data1->stem_arr, *stem_arr2 = data2->stem_arr;
> >         bool skipped1 = false, skipped2 = false;
> >
> >         i = 0;
> >         j = 0;
> >         while (i < nspec1 && j < nspec2) {
> > -               struct spec *spec1 = &spec_arr1[i];
> > -               struct spec *spec2 = &spec_arr2[j];
> > +               const struct spec *spec1 = &spec_arr1[i];
> > +               const struct spec *spec2 = &spec_arr2[j];
> >
> >                 /*
> >                  * Because sort_specs() moves exact pathnames to the
> > @@ -1297,8 +1297,8 @@ static enum selabel_cmp_result cmp(struct selabel_handle *h1,
> >                 if (spec2->stem_id == -1 && spec1->stem_id != -1)
> >                         return incomp(spec1, spec2, "stem_id", i, j);
> >                 if (spec1->stem_id != -1 && spec2->stem_id != -1) {
> > -                       struct stem *stem1 = &stem_arr1[spec1->stem_id];
> > -                       struct stem *stem2 = &stem_arr2[spec2->stem_id];
> > +                       const struct stem *stem1 = &stem_arr1[spec1->stem_id];
> > +                       const struct stem *stem2 = &stem_arr2[spec2->stem_id];
> >                         if (stem1->len != stem2->len ||
> >                             strncmp(stem1->buf, stem2->buf, stem1->len))
> >                                 return incomp(spec1, spec2, "stem", i, j);
> > diff --git a/libselinux/src/label_internal.h b/libselinux/src/label_internal.h
> > index 273a630a..bc5a6928 100644
> > --- a/libselinux/src/label_internal.h
> > +++ b/libselinux/src/label_internal.h
> > @@ -98,8 +98,8 @@ struct selabel_handle {
> >                                                     const char *key,
> >                                                     const char **aliases,
> >                                                     int type);
> > -       enum selabel_cmp_result (*func_cmp)(struct selabel_handle *h1,
> > -                                           struct selabel_handle *h2);
> > +       enum selabel_cmp_result (*func_cmp)(const struct selabel_handle *h1,
> > +                                           const struct selabel_handle *h2);
> >
> >         /* supports backend-specific state information */
> >         void *data;
> > --
> > 2.40.1
> >




[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux