Re: [libvirt PATCH 06/11] udevGetIntSysfsAttr: Return -1 for missing attributes

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

 



On Thu, Jan 28, 2021 at 11:24:36 +0100, Tim Wiederhake wrote:
> If "udevGetDeviceSysfsAttr()" returns NULL, "udevGetIntSysfsAttr"
> would return "0", indicating success, without writing to "value".
> 
> This was found by clang-tidy's
> "clang-analyzer-core.UndefinedBinaryOperatorResult" check in
> function "udevProcessCCW", flagging a read on the potentially
> uninitialized variable "online".
> 
> Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
> ---
>  src/node_device/node_device_udev.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
> index 55a2731681..d5a12bab0e 100644
> --- a/src/node_device/node_device_udev.c
> +++ b/src/node_device/node_device_udev.c
> @@ -254,7 +254,10 @@ udevGetIntSysfsAttr(struct udev_device *udev_device,
>  
>      str = udevGetDeviceSysfsAttr(udev_device, attr_name);
>  
> -    if (str && virStrToLong_i(str, NULL, base, value) < 0) {
> +    if (!str)
> +        return -1;

In this case an error wouldn't be reported any more.

> +
> +    if (virStrToLong_i(str, NULL, base, value) < 0) {
>          virReportError(VIR_ERR_INTERNAL_ERROR,
>                         _("Failed to convert '%s' to int"), str);

while here it was

>          return -1;
> -- 
> 2.26.2
> 




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux