qemu-devel
[Top][All Lists]
Advanced

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

Re: Missing Null check


From: Philippe Mathieu-Daudé
Subject: Re: Missing Null check
Date: Wed, 18 Mar 2020 09:14:30 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0

On 3/17/20 9:40 PM, Mansour Ahmadi wrote:
Is a NULL check on 'drv1->format_name' missing here?
https://github.com/qemu/qemu/blob/cc818a2148c5f321bdeb8e5564bdb2914e824600/block.c#L400-L403

if(!strcmp(drv1->format_name, format_name)) {

This could be NULL indeed. I'd rather assertions in the entry function, bdrv_register():

-- >8 --
diff --git a/block.c b/block.c
index a2542c977b..6b984dc883 100644
--- a/block.c
+++ b/block.c
@@ -363,6 +363,7 @@ char *bdrv_get_full_backing_filename(BlockDriverState *bs, Error **errp)

 void bdrv_register(BlockDriver *bdrv)
 {
+    assert(bdrv->format_name);
     QLIST_INSERT_HEAD(&bdrv_drivers, bdrv, list);
 }

---

While it is checked in similar case:
https://github.com/qemu/qemu/blob/cc818a2148c5f321bdeb8e5564bdb2914e824600/block.c#L797-L800

if(drv1->protocol_name&& !strcmp(drv1->protocol_name, protocol)) {

Because 'protocol_name' is optional.

Regards,

Phil.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]