nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [ndctl PATCH 1/2] ndctl: fix potential null dereference in the smart error handler
@ 2018-08-11  0:40 Vishal Verma
  2018-08-11  0:40 ` [ndctl PATCH 2/2] ndctl, udev: fix a resource leak in save_unsafe_shutdown_count Vishal Verma
  2018-08-13 14:29 ` [ndctl PATCH 1/2] ndctl: fix potential null dereference in the smart error handler Keith Busch
  0 siblings, 2 replies; 3+ messages in thread
From: Vishal Verma @ 2018-08-11  0:40 UTC (permalink / raw)
  To: linux-nvdimm

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.

Cc: Keith Busch <keith.busch@intel.com>
Fixes: ba17700bf227 ("ndctl, intel: Fallback to smart cached shutdown_count")
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/lib/intel.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/ndctl/lib/intel.c b/ndctl/lib/intel.c
index 00c65a5..b1254bb 100644
--- a/ndctl/lib/intel.c
+++ b/ndctl/lib/intel.c
@@ -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;
-- 
2.14.4

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-08-13 14:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-11  0:40 [ndctl PATCH 1/2] ndctl: fix potential null dereference in the smart error handler Vishal Verma
2018-08-11  0:40 ` [ndctl PATCH 2/2] ndctl, udev: fix a resource leak in save_unsafe_shutdown_count Vishal Verma
2018-08-13 14:29 ` [ndctl PATCH 1/2] ndctl: fix potential null dereference in the smart error handler Keith Busch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).