ndctl: fix potential null dereference in the smart error handler
Vishal Verma
maintainerPATCH 1/2 ndctl: fix potential null dereference in the smart error handler
Static analysis reports that can potentially dereference a NULL pointer in the smart cmd error handler. This can particular instance won't ever be hit in practice as the handler is only registered for smart commands, and smart commands are currently only DIMM commands, and will always have a dimm object. However for completeness, and to avoid future errors, we should perform a NULL check in the handler anyway.
--- ndctl/lib/intel.c | 3 +++ 1 file changed, 3 insertions(+)
ndctl/lib/intel.c +3 -0
@@ -67,6 +67,9 @@ static int intel_smart_handle_error(struct ndctl_cmd *cmd)char *path =NULL , shutdown_count[16 ] = {};int fd, rc = cmd->status; +if (!dimm) +return 0 ; +if (asprintf (&path,DEF_TMPFS_DIR "/%s/usc" ,ndctl_dimm_get_devname (dimm)) <0 )return rc;
Signature · 6 lines
2.14.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Vishal Verma
maintainerPATCH 2/2 ndctl, udev: fix a resource leak in save_unsafe_shutdown_count
Static analysis reports that we leak the 'fd' in the above function. Fix by adding a proper cleanup path that closes it.
--- ndctl/ndctl-udev.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
ndctl/ndctl-udev.c +5 -2
@@ -110,10 +110,13 @@ static void save_unsafe_shutdown_count(struct ndctl_dimm *dimm, goto free_usc;if (snprintf (count,sizeof (count),"%u\n" , shutdown) <0 ) - goto free_usc; + goto close_fd;if (write (fd, count,strlen (count)) <0 ) - goto free_usc; + goto close_fd; + + close_fd: +close (fd); free_usc:free (usc); free_path:
Signature · 6 lines
2.14.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Quoted 6 lines · Vishal Verma
Static analysis reports that can potentially dereference a NULL pointer in the smart cmd error handler. This can particular instance won't ever be hit in practice as the handler is only registered for smart commands, and smart commands are currently only DIMM commands, and will always have a dimm object. However for completeness, and to avoid future errors, we should perform a NULL check in the handler anyway.
Hmm, I purposefully didn't have the NULL check because the dimm is never not set in this path. Looks like a false positive, but the NULL check is harmless.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm