From nobody Fri May 10 11:42:31 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=quarantine) header.from=swemel.ru ARC-Seal: i=1; a=rsa-sha256; t=1694167667; cv=none; d=zohomail.com; s=zohoarc; b=PiorDzz5ugo5fapbcwg5ZF9ubEq/TAwM+zS601Qf1n9CklngBN1mR+HNVJBLUGbq/sq1ckOOLpxE6psTfUxPDOh2n/H9ZZ+dNi7KLYmW2msXU0XY0tEWYkipIfptitI2PjfkG4rqQNjPszHE3RiJcQ7a/r6544hOYVQNzfyep/g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694167667; 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=FxADK5/60IukXtzlX0o3l2beXb48ExbrnnWWmMyl8ZY=; b=FSLC67V6sQQOvKx+3wYMIYGZiVAqzswB1odz9xM27/K1WDBMDXmo5B3TMm6HUDQLHh5tA2Z/MMVRMW6obX6kdHBt4g8AlbdDmhj6IEIRXDHluu0di/QSGaUwvGENWCSkkpk9BtJzvnBxkFHnTj68n/CfqwagpIuIePKohmkU77U= 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=quarantine) 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 1694167667202493.39299260063865; Fri, 8 Sep 2023 03:07:47 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-597-Tww6O8-2O_GSEzrmStbCEA-1; Fri, 08 Sep 2023 06:07:40 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 6A441101CA84; Fri, 8 Sep 2023 10:07:38 +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 3EE9221EE566; Fri, 8 Sep 2023 10:07:36 +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 B521C194658F; Fri, 8 Sep 2023 10:07:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AC01B194658C for ; Fri, 8 Sep 2023 10:07:34 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 88DD363F78; Fri, 8 Sep 2023 10:07:34 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8247763F67 for ; Fri, 8 Sep 2023 10:07:34 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 3FC57101CA82 for ; Fri, 8 Sep 2023 10:07:34 +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-630-6Nb3C5ZxNmSFhsLsulafVw-1; Fri, 08 Sep 2023 06:07:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694167666; 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=FxADK5/60IukXtzlX0o3l2beXb48ExbrnnWWmMyl8ZY=; b=VWyW8ZybIhavfdbExTcOFSUhR7HTy4YBK87Aeq7I7aEwqsFChvllK+x8oXcBjujHcYVBwU QS0tu06xgwMPNRtKTA0uSWvT0nAavHp8vfnvi13FWTJvmfkA6UW2i4e3zuonlBV8csS/Vi FaDasZOErjzg/bn5Om+GlQDP32DYbDY= X-MC-Unique: Tww6O8-2O_GSEzrmStbCEA-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: 6Nb3C5ZxNmSFhsLsulafVw-1 From: Dmitry Frolov To: libvir-list@redhat.com Subject: [PATCH] interface: fix udev_device_get_sysattr_value return value check Date: Fri, 8 Sep 2023 13:06:43 +0300 Message-Id: <20230908100642.78147-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.5 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.6 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: 1694167669793100001 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. Signed-off-by: Dmitry Frolov --- src/interface/interface_backend_udev.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/interface/interface_backend_udev.c b/src/interface/interfa= ce_backend_udev.c index a0485ddd21..c820b3ccdf 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -355,10 +355,11 @@ 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))) + 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(NULLSTR(udev_device_get_sysattr_value(dev, "opers= tate")), "up"); =20 def =3D udevGetMinimalDefForDevice(dev); if (!virConnectListAllInterfacesCheckACL(conn, def)) { @@ -964,9 +965,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 +1090,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(NULLSTR(udev_device_get_sysattr_value(dev, "operstate= ")), "up"); =20 udev_device_unref(dev); =20 --=20 2.34.1