diff mbox

[2/2] ipmi: don't try to open a NULL filename

Message ID 1493103101-25165-3-git-send-email-clg@kaod.org
State New
Headers show

Commit Message

Cédric Le Goater April 25, 2017, 6:51 a.m. UTC
Currenlty, the code relies on the fact that open() handles NULL
filenames but that can cause an error with new clang:

  hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1,
  which is declared to never be null

Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 hw/ipmi/ipmi_bmc_sim.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Eric Blake April 25, 2017, 1:18 p.m. UTC | #1
On 04/25/2017 01:51 AM, Cédric Le Goater wrote:
> Currenlty, the code relies on the fact that open() handles NULL
> filenames but that can cause an error with new clang:

POSIX doesn't require it to work. Linux is nice and gives you EFAULT,
but there are systems where open(NULL) crashes with SIGSEGV.  The clang
warning is correct.

> 
>   hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1,
>   which is declared to never be null
> 
> Signed-off-by: Cédric Le Goater <clg@kaod.org>
> ---
>  hw/ipmi/ipmi_bmc_sim.c | 5 +++++
>  1 file changed, 5 insertions(+)

Reviewed-by: Eric Blake <eblake@redhat.com>
Peter Maydell April 25, 2017, 1:31 p.m. UTC | #2
On 25 April 2017 at 07:51, Cédric Le Goater <clg@kaod.org> wrote:
> Currenlty, the code relies on the fact that open() handles NULL
> filenames but that can cause an error with new clang:
>
>   hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1,
>   which is declared to never be null

This isn't "new clang", incidentally, it's just clang with the
runtime-static-analysis enabled, which causes warnings to be
printed at runtime for undefined behaviours. You can enable
this by passing configure --extra-cflags=-fsanitize=undefined .
(I have clang 3.8.0 here.)

thanks
-- PMM
Cédric Le Goater April 25, 2017, 2:06 p.m. UTC | #3
On 04/25/2017 03:31 PM, Peter Maydell wrote:
> On 25 April 2017 at 07:51, Cédric Le Goater <clg@kaod.org> wrote:
>> Currenlty, the code relies on the fact that open() handles NULL
>> filenames but that can cause an error with new clang:
>>
>>   hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1,
>>   which is declared to never be null
> 
> This isn't "new clang", incidentally, it's just clang with the
> runtime-static-analysis enabled, which causes warnings to be
> printed at runtime for undefined behaviours. You can enable
> this by passing configure --extra-cflags=-fsanitize=undefined .
> (I have clang 3.8.0 here.)

OK. So I have now reproduced the issue on a f24. That made be 
realize that the IPMI tests check for the arch they are being 
run on and that more changes are required for them to run on 
ppc64. 

We can drop patch 1/2. Tell me if you want a resend.

Thanks,

C.
David Gibson April 26, 2017, 2:42 a.m. UTC | #4
On Tue, Apr 25, 2017 at 08:51:41AM +0200, Cédric Le Goater wrote:
> Currenlty, the code relies on the fact that open() handles NULL
> filenames but that can cause an error with new clang:
> 
>   hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1,
>   which is declared to never be null
> 
> Signed-off-by: Cédric Le Goater <clg@kaod.org>

Since my ppc-for-2.10 pull request has been held up because of this
anyway, tather than just apply this on top, I've folded it into your
earlier patch which caused the bug - that way we won't break bisect.

> ---
>  hw/ipmi/ipmi_bmc_sim.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c
> index 155561d06614..277c28cb40ed 100644
> --- a/hw/ipmi/ipmi_bmc_sim.c
> +++ b/hw/ipmi/ipmi_bmc_sim.c
> @@ -1899,6 +1899,10 @@ static void ipmi_fru_init(IPMIFru *fru)
>      int fsize;
>      int size = 0;
>  
> +    if (!fru->filename) {
> +        goto out;
> +    }
> +
>      fsize = get_image_size(fru->filename);
>      if (fsize > 0) {
>          size = QEMU_ALIGN_UP(fsize, fru->areasize);
> @@ -1910,6 +1914,7 @@ static void ipmi_fru_init(IPMIFru *fru)
>          }
>      }
>  
> +out:
>      if (!fru->data) {
>          /* give one default FRU */
>          size = fru->areasize;
David Gibson April 26, 2017, 2:43 a.m. UTC | #5
On Tue, Apr 25, 2017 at 04:06:17PM +0200, Cédric Le Goater wrote:
> On 04/25/2017 03:31 PM, Peter Maydell wrote:
> > On 25 April 2017 at 07:51, Cédric Le Goater <clg@kaod.org> wrote:
> >> Currenlty, the code relies on the fact that open() handles NULL
> >> filenames but that can cause an error with new clang:
> >>
> >>   hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1,
> >>   which is declared to never be null
> > 
> > This isn't "new clang", incidentally, it's just clang with the
> > runtime-static-analysis enabled, which causes warnings to be
> > printed at runtime for undefined behaviours. You can enable
> > this by passing configure --extra-cflags=-fsanitize=undefined .
> > (I have clang 3.8.0 here.)
> 
> OK. So I have now reproduced the issue on a f24. That made be 
> realize that the IPMI tests check for the arch they are being 
> run on and that more changes are required for them to run on 
> ppc64. 
> 
> We can drop patch 1/2. Tell me if you want a resend.

No, that's fine.  A patch to enable the tests on ppc properly ASAP
would be great, though.
Cédric Le Goater April 26, 2017, 6:05 a.m. UTC | #6
On 04/26/2017 04:42 AM, David Gibson wrote:
> On Tue, Apr 25, 2017 at 08:51:41AM +0200, Cédric Le Goater wrote:
>> Currenlty, the code relies on the fact that open() handles NULL
>> filenames but that can cause an error with new clang:
>>
>>   hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1,
>>   which is declared to never be null
>>
>> Signed-off-by: Cédric Le Goater <clg@kaod.org>
> 
> Since my ppc-for-2.10 pull request has been held up because of this
> anyway, tather than just apply this on top, I've folded it into your
> earlier patch which caused the bug - that way we won't break bisect.

Yes that is the best option. 

Thanks,

C.
Cédric Le Goater April 26, 2017, 6:41 a.m. UTC | #7
On 04/26/2017 04:43 AM, David Gibson wrote:
> On Tue, Apr 25, 2017 at 04:06:17PM +0200, Cédric Le Goater wrote:
>> On 04/25/2017 03:31 PM, Peter Maydell wrote:
>>> On 25 April 2017 at 07:51, Cédric Le Goater <clg@kaod.org> wrote:
>>>> Currenlty, the code relies on the fact that open() handles NULL
>>>> filenames but that can cause an error with new clang:
>>>>
>>>>   hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1,
>>>>   which is declared to never be null
>>>
>>> This isn't "new clang", incidentally, it's just clang with the
>>> runtime-static-analysis enabled, which causes warnings to be
>>> printed at runtime for undefined behaviours. You can enable
>>> this by passing configure --extra-cflags=-fsanitize=undefined .
>>> (I have clang 3.8.0 here.)
>>
>> OK. So I have now reproduced the issue on a f24. That made be 
>> realize that the IPMI tests check for the arch they are being 
>> run on and that more changes are required for them to run on 
>> ppc64. 
>>
>> We can drop patch 1/2. Tell me if you want a resend.
> 
> No, that's fine.  A patch to enable the tests on ppc properly ASAP
> would be great, though.

Yes, it would. I need to understand what is behind : 

	qtest_irq_intercept_in(...)

C.
diff mbox

Patch

diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c
index 155561d06614..277c28cb40ed 100644
--- a/hw/ipmi/ipmi_bmc_sim.c
+++ b/hw/ipmi/ipmi_bmc_sim.c
@@ -1899,6 +1899,10 @@  static void ipmi_fru_init(IPMIFru *fru)
     int fsize;
     int size = 0;
 
+    if (!fru->filename) {
+        goto out;
+    }
+
     fsize = get_image_size(fru->filename);
     if (fsize > 0) {
         size = QEMU_ALIGN_UP(fsize, fru->areasize);
@@ -1910,6 +1914,7 @@  static void ipmi_fru_init(IPMIFru *fru)
         }
     }
 
+out:
     if (!fru->data) {
         /* give one default FRU */
         size = fru->areasize;