diff mbox series

[ndctl,1/2] ndctl: fix potential null dereference in the smart error handler

Message ID 20180811004053.15392-1-vishal.l.verma@intel.com (mailing list archive)
State New, archived
Headers show
Series [ndctl,1/2] ndctl: fix potential null dereference in the smart error handler | expand

Commit Message

Verma, Vishal L Aug. 11, 2018, 12:40 a.m. UTC
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(+)

Comments

Keith Busch Aug. 13, 2018, 2:29 p.m. UTC | #1
On Fri, Aug 10, 2018 at 06:40:52PM -0600, Vishal Verma wrote:
> 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.
diff mbox series

Patch

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;