Re: [RFC PATCH v2 16/27] libselinux: update string_to_mode()

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

 



On Mon, Aug 14, 2023 at 9:41 AM Christian Göttsche
<cgzones@xxxxxxxxxxxxxx> wrote:
>
> Drop parameter NULL check since the only caller does a NULL check on the
> argument.
>
> Avoid strlen(3) call by comparing by hand.
>
> Drop unreachable return statement.
>
> Signed-off-by: Christian Göttsche <cgzones@xxxxxxxxxxxxxx>

Acked-by: James Carter <jwcart2@xxxxxxxxx>

> ---
>  libselinux/src/label_file.h | 15 ++++-----------
>  1 file changed, 4 insertions(+), 11 deletions(-)
>
> diff --git a/libselinux/src/label_file.h b/libselinux/src/label_file.h
> index 190bc175..1363c83c 100644
> --- a/libselinux/src/label_file.h
> +++ b/libselinux/src/label_file.h
> @@ -97,15 +97,10 @@ struct saved_data {
>         struct selabel_sub *subs;
>  };
>
> -static inline mode_t string_to_mode(char *mode)
> +static inline mode_t string_to_mode(const char *mode)
>  {
> -       size_t len;
> -
> -       if (!mode)
> -               return 0;
> -       len = strlen(mode);
> -       if (mode[0] != '-' || len != 2)
> -               return -1;
> +       if (mode[0] != '-' || mode[1] == '\0' || mode[2] != '\0')
> +               return (mode_t)-1;
>         switch (mode[1]) {
>         case 'b':
>                 return S_IFBLK;
> @@ -122,10 +117,8 @@ static inline mode_t string_to_mode(char *mode)
>         case '-':
>                 return S_IFREG;
>         default:
> -               return -1;
> +               return (mode_t)-1;
>         }
> -       /* impossible to get here */
> -       return 0;
>  }
>
>  static inline int grow_specs(struct saved_data *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