Re: [PATCH v2 1/3] Fix potential null pointer dereference

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

 



On Fri, 2021-11-19 at 16:56 +0800, lixiaokeng wrote:
> udev_device_* may return NULL, check it.
> 
> Signed-off-by: Lixiaokeng <lixiaokeng@xxxxxxxxxx>
> ---
>  libmultipath/discovery.c    |  8 +++++---
>  libmultipath/foreign/nvme.c |  4 +++-
>  libmultipath/util.c         | 10 +++++++++-
>  3 files changed, 17 insertions(+), 5 deletions(-)
> 
> diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
> index f25fe9e3..07ebe7d5 100644
> --- a/libmultipath/discovery.c
> +++ b/libmultipath/discovery.c
> 
> diff --git a/libmultipath/util.c b/libmultipath/util.c
> index ea858409..3d036e19 100644
> --- a/libmultipath/util.c
> +++ b/libmultipath/util.c
> @@ -168,6 +168,7 @@ size_t strlcat(char * restrict dst, const char *
> restrict src, size_t size)
>  int devt2devname(char *devname, int devname_len, const char *devt)
>  {
>         struct udev_device *u_dev;
> +       const char * dev_name;
>         int r;
> 
>         if (!devname || !devname_len || !devt)
> @@ -178,7 +179,14 @@ int devt2devname(char *devname, int devname_len,
> const char *devt)
>                 condlog(0, "\"%s\": invalid major/minor numbers, not
> found in sysfs", devt);
>                 return 1;
>         }
> -       r = strlcpy(devname, udev_device_get_sysname(u_dev),
> devname_len);
> +
> +       dev_name = udev_device_get_sysname(u_dev);
> +       if (!dev_name) {
> +               condlog(2, "\"%s\": fail to get sysname\n", devt);
> +               udev_device_unref(u_dev);
> +               return 1;
> +       }
> +       r = strlcpy(devname, dev_name, devname_len);

No condlog() here, please. The only caller, sysfs_check_holders(),
already logs an error from devt2devname().

Martin





--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/dm-devel





[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux