multipath-tools series: some codeclean
v2 cover multipath-tools series: some codeclean
*** BLURB HERE ***
lixiaokeng (3):
Fix potential null pointer dereference
remove unnecessary memset
remove unnecessary free
libmultipath/discovery.c | 8 +++++--- libmultipath/foreign/nvme.c | 4 +++- libmultipath/log.c | 1 - libmultipath/prioritizers/weightedpath.c | 3 +-- libmultipath/util.c | 10 +++++++++- multipathd/waiter.c | 1 - 6 files changed, 18 insertions(+), 9 deletions(-)
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
PATCH v2 1/3 Fix potential null pointer dereference
udev_device_* may return NULL, check it.
--- libmultipath/discovery.c | 8 +++++--- libmultipath/foreign/nvme.c | 4 +++- libmultipath/util.c | 10 +++++++++- 3 files changed, 17 insertions(+), 5 deletions(-)
libmultipath/discovery.c +5 -3
@@ -388,8 +388,10 @@ sysfs_get_tgt_nodename(struct path *pp, char *node)if (value && !strcmp (value,"usb" )) { pp->sg_id.proto_id =SCSI_PROTOCOL_USB ; tgtname =udev_device_get_sysname (tgtdev); -strlcpy (node, tgtname,NODE_NAME_SIZE ); -return 0 ; +if (tgtname) { +strlcpy (node, tgtname,NODE_NAME_SIZE ); +return 0 ; + } } tgtdev =udev_device_get_parent (tgtdev); }
@@ -803,7 +805,7 @@ sysfs_set_nexus_loss_tmo(struct multipath *mpp, struct path *pp) parent = udev_device_get_parent(parent)) {const char *ed =udev_device_get_sysname (parent); -if (!strncmp (ed, ed_str,sizeof (ed_str) -1 )) { +if (ed && !strncmp (ed, ed_str,sizeof (ed_str) -1 )) { end_dev_id = ed;break ; }
libmultipath/foreign/nvme.c +3 -1
@@ -184,7 +184,9 @@ static int snprint_nvme_map(const struct gen_multipath *gmp, "firmware_rev"));case 'r' : val =udev_device_get_sysattr_value (nvm->udev,"ro" ); -if (val[0 ] ==1 ) +if (!val) +return append_strbuf_str (buff,"undef" ); +else if (val[0 ] ==1 )return append_strbuf_str (buff,"ro" );else return append_strbuf_str (buff,"rw" );
libmultipath/util.c +9 -1
@@ -168,6 +168,7 @@ size_t strlcat(char * restrict dst, const char * restrict src, size_t size)int devt2devname (char *devname,int devname_len,const char *devt) {struct udev_device *u_dev; +const char * dev_name;int r;if (!devname || !devname_len || !devt)
@@ -178,7 +179,14 @@ int devt2devname(char *devname, int devname_len, const char *devt)condlog (0 ,"\"%s\": invalid major/minor numbers, not found in sysfs" , devt);return 1 ; } - r =strlcpy (devname,udev_device_get_sysname (u_dev), devname_len); + + dev_name =udev_device_get_sysname (u_dev); +if (!dev_name) { +condlog (2 ,"\"%s\": fail to get sysname\n" , devt); +udev_device_unref (u_dev); +return 1 ; + } + r =strlcpy (devname, dev_name, devname_len);udev_device_unref (u_dev);return !(r < devname_len);
Signature · 4 lines
-- dm-devel mailing list [email protected] https://listman.redhat.com/mailman/listinfo/dm-devel
Re: [dm-devel] [PATCH v2 1/3] Fix potential null pointer dereference
Quoted 35 lines · lixiaokeng
udev_device_* may return NULL, check it.
Signed-off-by Lixiaokeng <[email protected]>---
libmultipath/discovery.c | 8 +++++---
libmultipath/foreign/nvme.c | 4 +++-
libmultipath/util.c | 10 +++++++++-3 files changed, 17 insertions(+), 5 deletions(-)libmultipath/discovery.c +0
-0libmultipath/util.c +1
-0@@ -168,6 +168,7 @@ size_t strlcat(char * restrict dst, const char * restrict src, size_t size) int devt2devname(char *devname, int devname_len, const char *devt) { struct udev_device *u_dev; + const char * dev_name; int r;if (!devname || !devname_len || !devt)
libmultipath/util.c +0
-0@@ -178,7 +179,14 @@ int devt2devname(char *devname, int devname_len, const char *devt)condlog(0, "\"%s\": invalid major/minor numbers, not found in sysfs", devt);
return 1;
}
- r =strlcpy(devname, udev_device_get_sysname(u_dev), devname_len);
Quoted 8 lines
+
+ dev_name =udev_device_get_sysname(u_dev);
+ if (!dev_name) {
+ condlog(2, "\"%s\": fail to get sysname\n", devt); + udev_device_unref(u_dev);
+ return 1;
+ }
+ r =strlcpy(devname, dev_name, devname_len);
No condlog() here, please. The only caller, sysfs_check_holders(), already logs an error from devt2devname().
Martin
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
PATCH v2 2/3 remove unnecessary memset
In reply to lixiaokengMALLOC will set memory zero. memset is unnecessary. Remove it.
--- libmultipath/log.c | 1 - multipathd/waiter.c | 1 - 2 files changed, 2 deletions(-)
libmultipath/log.c +0 -1
@@ -57,7 +57,6 @@ static int logarea_init (int size)FREE (la);return 1 ; } -memset (la->start,0 , size); la->empty =1 ; la->end = la->start + size;
multipathd/waiter.c +0 -1
@@ -33,7 +33,6 @@ static struct event_thread *alloc_waiter (void)struct event_thread *wp; wp = (struct event_thread *)MALLOC (sizeof (struct event_thread )); -memset (wp,0 ,sizeof (struct event_thread ));return wp; }
--
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Re: [dm-devel] [PATCH v2 2/3] remove unnecessary memset
Quoted 4 lines · lixiaokeng
MALLOC will set memory zero. memset is unnecessary. Remove it.
Signed-off-by Lixiaokeng <[email protected]>
Thanks. Nitpick: this patch and 3/3 were already reviewed by Ben. Please simplify our lives by including that information in the resent patch.
Regards
Martin
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
PATCH v2 3/3 remove unnecessary free
In reply to lixiaokengarg will be free by cleanup_charp. FREE(args)
is unnecessary before return. Remove it.
--- libmultipath/prioritizers/weightedpath.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
libmultipath/prioritizers/weightedpath.c +1 -2
@@ -75,13 +75,12 @@ int prio_path_weight(struct path *pp, char *prio_args)if (!prio_args)return priority; - arg = temp =STRDUP (prio_args); + arg = temp =strdup (prio_args); regex =get_next_string (&temp, split_char);/* Return default priority if the argument is not parseable */ if (!regex) { -FREE (arg);return priority; }
Signature · 4 lines
-- dm-devel mailing list [email protected] https://listman.redhat.com/mailman/listinfo/dm-devel