diff mbox series

[3/4] util: Fix for NULL dereference

Message ID 20181110125624.1168-4-radoslaw.biernacki@linaro.org
State Superseded
Headers show
Series util: Fixing libvirt errors on cavium/thunder-nicvf | expand

Commit Message

Radoslaw Biernacki Nov. 10, 2018, 12:56 p.m. UTC
The device xml parser code does not set "model" while parsing
<interface type='hostdev'>
  <source>
    <address type='pci' domain='0x0002' bus='0x01' slot='0x00' function='0x2'/>
  </source>
</interface>
virDomainDefPtr def->nets[i]->model can be NULL while latter compares strings with
STREQ instead of STREQ_NULLABLE.

Fixes: ac47e4a6225 (qemu: replace "def->nets[i]" with "net" and "def->sounds[i]" with "sound")
Fixes: c7fc151eec7 (qemu: assign virtio devices to PCIe slot when appropriate)
Signed-off-by: Radoslaw Biernacki <radoslaw.biernacki@linaro.org>

---
 src/qemu/qemu_domain_address.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

-- 
2.14.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Comments

Michal Prívozník Nov. 15, 2018, 11:23 a.m. UTC | #1
On 11/10/2018 01:56 PM, Radoslaw Biernacki wrote:
> The device xml parser code does not set "model" while parsing

> <interface type='hostdev'>

>   <source>

>     <address type='pci' domain='0x0002' bus='0x01' slot='0x00' function='0x2'/>

>   </source>

> </interface>

> virDomainDefPtr def->nets[i]->model can be NULL while latter compares strings with

> STREQ instead of STREQ_NULLABLE.

> 

> Fixes: ac47e4a6225 (qemu: replace "def->nets[i]" with "net" and "def->sounds[i]" with "sound")

> Fixes: c7fc151eec7 (qemu: assign virtio devices to PCIe slot when appropriate)

> Signed-off-by: Radoslaw Biernacki <radoslaw.biernacki@linaro.org>

> ---

>  src/qemu/qemu_domain_address.c | 11 +++++------

>  1 file changed, 5 insertions(+), 6 deletions(-)

> 

> diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c

> index 27c9bfb946..15d25481d8 100644

> --- a/src/qemu/qemu_domain_address.c

> +++ b/src/qemu/qemu_domain_address.c

> @@ -232,8 +232,7 @@ qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def)

>      for (i = 0; i < def->nnets; i++) {

>          virDomainNetDefPtr net = def->nets[i];

>  

> -        if (net->model &&

> -            STREQ(net->model, "spapr-vlan")) {

> +        if (STREQ_NULLABLE(net->model, "spapr-vlan")) {

>              net->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO;

>          }


We don't require curly braces around single line bodies. Actually the
opposite, our coding style says there should be none. This exception to
the rule was discussed many times but without any result. Anyway, 'make
syntax-check' would have caught this.

>  

> @@ -325,7 +324,7 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr def,

>          virDomainNetDefPtr net = def->nets[i];

>  

>          if (net->model &&

> -            STREQ(net->model, "virtio") &&

> +            STREQ_NULLABLE(net->model, "virtio") &&


Looks like you've forgotten to remove net->model check ;-)

>              net->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {

>              net->info.type = type;

>          }

> @@ -634,14 +633,14 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,

>           * addresses for other hostdev devices.

>           */

>          if (net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV ||

> -            STREQ(net->model, "usb-net")) {

> +            STREQ_NULLABLE(net->model, "usb-net")) {

>              return 0;

>          }

>  

> -        if (STREQ(net->model, "virtio"))

> +        if (STREQ_NULLABLE(net->model, "virtio"))

>              return  virtioFlags;

>  

> -        if (STREQ(net->model, "e1000e"))

> +        if (STREQ_NULLABLE(net->model, "e1000e"))

>              return pcieFlags;

>  

>          return pciFlags;

> 


The rest looks okay.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Radoslaw Biernacki Nov. 17, 2018, 7:41 p.m. UTC | #2
On Thu, 15 Nov 2018 at 12:23, Michal Privoznik <mprivozn@redhat.com> wrote:

> On 11/10/2018 01:56 PM, Radoslaw Biernacki wrote:

> > The device xml parser code does not set "model" while parsing

> > <interface type='hostdev'>

> >   <source>

> >     <address type='pci' domain='0x0002' bus='0x01' slot='0x00'

> function='0x2'/>

> >   </source>

> > </interface>

> > virDomainDefPtr def->nets[i]->model can be NULL while latter compares

> strings with

> > STREQ instead of STREQ_NULLABLE.

> >

> > Fixes: ac47e4a6225 (qemu: replace "def->nets[i]" with "net" and

> "def->sounds[i]" with "sound")

> > Fixes: c7fc151eec7 (qemu: assign virtio devices to PCIe slot when

> appropriate)

> > Signed-off-by: Radoslaw Biernacki <radoslaw.biernacki@linaro.org>

> > ---

> >  src/qemu/qemu_domain_address.c | 11 +++++------

> >  1 file changed, 5 insertions(+), 6 deletions(-)

> >

> > diff --git a/src/qemu/qemu_domain_address.c

> b/src/qemu/qemu_domain_address.c

> > index 27c9bfb946..15d25481d8 100644

> > --- a/src/qemu/qemu_domain_address.c

> > +++ b/src/qemu/qemu_domain_address.c

> > @@ -232,8 +232,7 @@ qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr

> def)

> >      for (i = 0; i < def->nnets; i++) {

> >          virDomainNetDefPtr net = def->nets[i];

> >

> > -        if (net->model &&

> > -            STREQ(net->model, "spapr-vlan")) {

> > +        if (STREQ_NULLABLE(net->model, "spapr-vlan")) {

> >              net->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO;

> >          }

>

> We don't require curly braces around single line bodies. Actually the

> opposite, our coding style says there should be none. This exception to

> the rule was discussed many times but without any result. Anyway, 'make

> syntax-check' would have caught this.

>


Sorry Michal, overlooked that.
Fixed in v2.


>

> >

> > @@ -325,7 +324,7 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr

> def,

> >          virDomainNetDefPtr net = def->nets[i];

> >

> >          if (net->model &&

> > -            STREQ(net->model, "virtio") &&

> > +            STREQ_NULLABLE(net->model, "virtio") &&

>

> Looks like you've forgotten to remove net->model check ;-)

>

> >              net->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {

> >              net->info.type = type;

> >          }

> > @@ -634,14 +633,14 @@

> qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,

> >           * addresses for other hostdev devices.

> >           */

> >          if (net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV ||

> > -            STREQ(net->model, "usb-net")) {

> > +            STREQ_NULLABLE(net->model, "usb-net")) {

> >              return 0;

> >          }

> >

> > -        if (STREQ(net->model, "virtio"))

> > +        if (STREQ_NULLABLE(net->model, "virtio"))

> >              return  virtioFlags;

> >

> > -        if (STREQ(net->model, "e1000e"))

> > +        if (STREQ_NULLABLE(net->model, "e1000e"))

> >              return pcieFlags;

> >

> >          return pciFlags;

> >

>

> The rest looks okay.

>

> Michal

>
<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, 15 Nov 2018 at 12:23, Michal Privoznik &lt;<a href="mailto:mprivozn@redhat.com">mprivozn@redhat.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 11/10/2018 01:56 PM, Radoslaw Biernacki wrote:<br>
&gt; The device xml parser code does not set &quot;model&quot; while parsing<br>
&gt; &lt;interface type=&#39;hostdev&#39;&gt;<br>
&gt;   &lt;source&gt;<br>
&gt;     &lt;address type=&#39;pci&#39; domain=&#39;0x0002&#39; bus=&#39;0x01&#39; slot=&#39;0x00&#39; function=&#39;0x2&#39;/&gt;<br>
&gt;   &lt;/source&gt;<br>
&gt; &lt;/interface&gt;<br>
&gt; virDomainDefPtr def-&gt;nets[i]-&gt;model can be NULL while latter compares strings with<br>
&gt; STREQ instead of STREQ_NULLABLE.<br>
&gt; <br>
&gt; Fixes: ac47e4a6225 (qemu: replace &quot;def-&gt;nets[i]&quot; with &quot;net&quot; and &quot;def-&gt;sounds[i]&quot; with &quot;sound&quot;)<br>
&gt; Fixes: c7fc151eec7 (qemu: assign virtio devices to PCIe slot when appropriate)<br>
&gt; Signed-off-by: Radoslaw Biernacki &lt;<a href="mailto:radoslaw.biernacki@linaro.org" target="_blank">radoslaw.biernacki@linaro.org</a>&gt;<br>
&gt; ---<br>
&gt;  src/qemu/qemu_domain_address.c | 11 +++++------<br>
&gt;  1 file changed, 5 insertions(+), 6 deletions(-)<br>
&gt; <br>
&gt; diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c<br>
&gt; index 27c9bfb946..15d25481d8 100644<br>
&gt; --- a/src/qemu/qemu_domain_address.c<br>
&gt; +++ b/src/qemu/qemu_domain_address.c<br>
&gt; @@ -232,8 +232,7 @@ qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def)<br>
&gt;      for (i = 0; i &lt; def-&gt;nnets; i++) {<br>
&gt;          virDomainNetDefPtr net = def-&gt;nets[i];<br>
&gt;  <br>
&gt; -        if (net-&gt;model &amp;&amp;<br>
&gt; -            STREQ(net-&gt;model, &quot;spapr-vlan&quot;)) {<br>
&gt; +        if (STREQ_NULLABLE(net-&gt;model, &quot;spapr-vlan&quot;)) {<br>
&gt;              net-&gt;info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO;<br>
&gt;          }<br>
<br>
We don&#39;t require curly braces around single line bodies. Actually the<br>
opposite, our coding style says there should be none. This exception to<br>
the rule was discussed many times but without any result. Anyway, &#39;make<br>
syntax-check&#39; would have caught this.<br></blockquote><div><br></div><div>Sorry Michal, overlooked that.</div><div>Fixed in v2.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
&gt;  <br>
&gt; @@ -325,7 +324,7 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr def,<br>
&gt;          virDomainNetDefPtr net = def-&gt;nets[i];<br>
&gt;  <br>
&gt;          if (net-&gt;model &amp;&amp;<br>
&gt; -            STREQ(net-&gt;model, &quot;virtio&quot;) &amp;&amp;<br>
&gt; +            STREQ_NULLABLE(net-&gt;model, &quot;virtio&quot;) &amp;&amp;<br>
<br>
Looks like you&#39;ve forgotten to remove net-&gt;model check ;-)<br>
<br>
&gt;              net-&gt;info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {<br>
&gt;              net-&gt;info.type = type;<br>
&gt;          }<br>
&gt; @@ -634,14 +633,14 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,<br>
&gt;           * addresses for other hostdev devices.<br>
&gt;           */<br>
&gt;          if (net-&gt;type == VIR_DOMAIN_NET_TYPE_HOSTDEV ||<br>
&gt; -            STREQ(net-&gt;model, &quot;usb-net&quot;)) {<br>
&gt; +            STREQ_NULLABLE(net-&gt;model, &quot;usb-net&quot;)) {<br>
&gt;              return 0;<br>
&gt;          }<br>
&gt;  <br>
&gt; -        if (STREQ(net-&gt;model, &quot;virtio&quot;))<br>
&gt; +        if (STREQ_NULLABLE(net-&gt;model, &quot;virtio&quot;))<br>
&gt;              return  virtioFlags;<br>
&gt;  <br>
&gt; -        if (STREQ(net-&gt;model, &quot;e1000e&quot;))<br>
&gt; +        if (STREQ_NULLABLE(net-&gt;model, &quot;e1000e&quot;))<br>
&gt;              return pcieFlags;<br>
&gt;  <br>
&gt;          return pciFlags;<br>
&gt; <br>
<br>
The rest looks okay.<br>
<br>
Michal<br>
</blockquote></div></div>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox series

Patch

diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 27c9bfb946..15d25481d8 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -232,8 +232,7 @@  qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def)
     for (i = 0; i < def->nnets; i++) {
         virDomainNetDefPtr net = def->nets[i];
 
-        if (net->model &&
-            STREQ(net->model, "spapr-vlan")) {
+        if (STREQ_NULLABLE(net->model, "spapr-vlan")) {
             net->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO;
         }
 
@@ -325,7 +324,7 @@  qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr def,
         virDomainNetDefPtr net = def->nets[i];
 
         if (net->model &&
-            STREQ(net->model, "virtio") &&
+            STREQ_NULLABLE(net->model, "virtio") &&
             net->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
             net->info.type = type;
         }
@@ -634,14 +633,14 @@  qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
          * addresses for other hostdev devices.
          */
         if (net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV ||
-            STREQ(net->model, "usb-net")) {
+            STREQ_NULLABLE(net->model, "usb-net")) {
             return 0;
         }
 
-        if (STREQ(net->model, "virtio"))
+        if (STREQ_NULLABLE(net->model, "virtio"))
             return  virtioFlags;
 
-        if (STREQ(net->model, "e1000e"))
+        if (STREQ_NULLABLE(net->model, "e1000e"))
             return pcieFlags;
 
         return pciFlags;