multipath-tools series: some codeclean
v3 cover multipath-tools series: some codeclean
Changes for v2 to v3:
0001: remove condlog.
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 | 9 ++++++++- multipathd/waiter.c | 1 - 6 files changed, 17 insertions(+), 9 deletions(-)
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
PATCH v3 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 | 9 ++++++++- 3 files changed, 16 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 +8 -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,13 @@ 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) { +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 v3 1/3] Fix potential null pointer dereference
Quoted 3 lines · lixiaokeng
udev_device_* may return NULL, check it.
Signed-off-by Lixiaokeng <[email protected]>
Quoted 65 lines
--- libmultipath/discovery.c | 8 +++++--- libmultipath/foreign/nvme.c | 4 +++- libmultipath/util.c | 9 ++++++++- 3 files changed, 16 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 +1
-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,13 @@ 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);
libmultipath/util.c int devt2devname(char *devname, int devname_len, const char *devt) · line 191
Quoted 10 lines
libmultipath/util.c +7
-0+ + dev_name =udev_device_get_sysname (u_dev); +if (!dev_name) { +udev_device_unref (u_dev); +return 1 ; + } + r =strlcpy (devname, dev_name, devname_len);udev_device_unref (u_dev);return !(r < devname_len);
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Re: [dm-devel] [PATCH v3 1/3] Fix potential null pointer dereference
In reply to lixiaokengQuoted 3 lines · lixiaokeng
udev_device_* may return NULL, check it.
Signed-off-by Lixiaokeng <[email protected]>
Thanks!
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
PATCH v3 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
PATCH v3 3/3 remove unnecessary free
In reply to lixiaokengargs 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