From nobody Fri May 10 16:02:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=none) header.from=swemel.ru ARC-Seal: i=1; a=rsa-sha256; t=1694178977; cv=none; d=zohomail.com; s=zohoarc; b=Dq3NgOF2EhJPiVVffvTSKBEXHSsvgiFMyST+5LyTj5dx428WDzNeAj1Ocjk3Knk7AO5u9BwikXYntPdHPTYftO+2k+5ZkJRJeH3+S3DCLZobjWaXYnBSRyLxNU6cmX0zFKSAiDo2ydzG7Cgw40Kei5yYMKdtdhCi6zduM8iUuCM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694178977; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=iXrCoYE418K9muZHTyyFVlhQOXgRXXw/SPKpnbTFXWE=; b=VnZwWY3oS2/w81VEO+qGhLlPk0gvSKqvxBmfVplDJPuiJsdrLpGh/vhxqxhYSheG2mq+6x99qAHzQRAdHSdV0UqQiWfBVoGBkkoh12BrHp12tvMHabNAxErSGAcNsUqz3SFeZXy397tYsPrOfd9kArilVw5TW0TZ8BOdb5hDkMs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1694178976547546.5581579601982; Fri, 8 Sep 2023 06:16:16 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-199-D8jyFyTwOs2piJ5UrDIwkg-1; Fri, 08 Sep 2023 09:16:13 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 448511C09CEA; Fri, 8 Sep 2023 13:16:10 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 484B640ED780; Fri, 8 Sep 2023 13:16:08 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CC565194658F; Fri, 8 Sep 2023 13:16:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 70494194658C for ; Fri, 8 Sep 2023 13:16:06 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3174F412F2D0; Fri, 8 Sep 2023 13:16:06 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast10.extmail.prod.ext.rdu2.redhat.com [10.11.55.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2AA8E40C6CCC for ; Fri, 8 Sep 2023 13:16:06 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0D0071C09CEA for ; Fri, 8 Sep 2023 13:16:06 +0000 (UTC) Received: from mx.swemel.ru (mx.swemel.ru [95.143.211.150]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-7R_zwNXVPD60xsuTbg1S3Q-1; Fri, 08 Sep 2023 09:16:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694178975; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=iXrCoYE418K9muZHTyyFVlhQOXgRXXw/SPKpnbTFXWE=; b=ae6wfjr11JQq3phOrRjzHoJcbKvLGvfxZt589WVtT9ZbUj1fdamagZNy4J63xOGRbAkae2 97D0FPdk0T/xtUAuCpcEKog5EKSaKa/QIZ9UX0AeizupkGAi46W3AoH1rf39L1pyHQPkvL z+SjPeFl/iF+f3X5Y80bVLHNhKLTz8M= X-MC-Unique: D8jyFyTwOs2piJ5UrDIwkg-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: 7R_zwNXVPD60xsuTbg1S3Q-1 From: Dmitry Frolov To: libvir-list@redhat.com Subject: [PATCH v2] interface: fix udev_device_get_sysattr_value return value check Date: Fri, 8 Sep 2023 16:15:29 +0300 Message-Id: <20230908131528.135170-1-frolov@swemel.ru> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Frolov Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: swemel.ru Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1694178980986100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Reviewing the code I found that return value of function udev_device_get_sysattr_value() is dereferenced without a check. udev_device_get_sysattr_value() may return NULL by number of reasons. v2: VIR_DEBUG added, replaced STREQ(NULLSTR()) with STREQ_NULLABLE() Signed-off-by: Dmitry Frolov --- src/interface/interface_backend_udev.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/interface/interface_backend_udev.c b/src/interface/interfa= ce_backend_udev.c index a0485ddd21..df7066727e 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -23,6 +23,7 @@ #include #include =20 +#include "virlog.h" #include "virerror.h" #include "virfile.h" #include "datatypes.h" @@ -40,6 +41,8 @@ =20 #define VIR_FROM_THIS VIR_FROM_INTERFACE =20 +VIR_LOG_INIT("interface.interface_backend_udev"); + struct udev_iface_driver { struct udev *udev; /* pid file FD, ensures two copies of the driver can't use the same ro= ot */ @@ -355,10 +358,13 @@ udevConnectListAllInterfaces(virConnectPtr conn, g_autoptr(virInterfaceDef) def =3D NULL; =20 path =3D udev_list_entry_get_name(dev_entry); - dev =3D udev_device_new_from_syspath(udev, path); + if (!(dev =3D udev_device_new_from_syspath(udev, path))) { + VIR_DEBUG("Skipping interface '%s'", NULLSTR(path)); + continue; + } name =3D udev_device_get_sysname(dev); macaddr =3D udev_device_get_sysattr_value(dev, "address"); - status =3D STREQ(udev_device_get_sysattr_value(dev, "operstate"), = "up"); + status =3D STREQ_NULLABLE(udev_device_get_sysattr_value(dev, "oper= state"), "up"); =20 def =3D udevGetMinimalDefForDevice(dev); if (!virConnectListAllInterfacesCheckACL(conn, def)) { @@ -964,9 +970,9 @@ udevGetIfaceDef(struct udev *udev, const char *name) =20 /* MTU */ mtu_str =3D udev_device_get_sysattr_value(dev, "mtu"); - if (virStrToLong_ui(mtu_str, NULL, 10, &mtu) < 0) { + if (!mtu_str || virStrToLong_ui(mtu_str, NULL, 10, &mtu) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not parse MTU value '%1$s'"), mtu_str); + _("Could not parse MTU value '%1$s'"), NULLSTR(mtu_str)); goto error; } ifacedef->mtu =3D mtu; @@ -1089,7 +1095,7 @@ udevInterfaceIsActive(virInterfacePtr ifinfo) goto cleanup; =20 /* Check if it's active or not */ - status =3D STREQ(udev_device_get_sysattr_value(dev, "operstate"), "up"= ); + status =3D STREQ_NULLABLE(udev_device_get_sysattr_value(dev, "operstat= e"), "up"); =20 udev_device_unref(dev); =20 --=20 2.34.1