From a20e32ad3381159a19588baa696c4dde754cbdf9 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Fri, 20 Mar 2009 12:29:20 +0000 Subject: [PATCH] Fixing NULL pointer dereferences accessing dev->d_sense git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@706 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/scst.h | 2 +- scst/src/scst_lib.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scst/include/scst.h b/scst/include/scst.h index 603cf9703..a37e2a479 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -2407,7 +2407,7 @@ static inline int scst_cmd_aborted(struct scst_cmd *cmd) /* Returns sense data format for cmd's dev */ static inline bool scst_get_cmd_dev_d_sense(struct scst_cmd *cmd) { - return cmd->dev->d_sense; + return (cmd->dev != NULL) ? cmd->dev->d_sense : 0; } /* diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 0f5b2446a..fbff1e1a4 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -141,8 +141,8 @@ void scst_set_cmd_error(struct scst_cmd *cmd, int key, int asc, int ascq) goto out; } - scst_set_sense(cmd->sense, SCST_SENSE_BUFFERSIZE, cmd->dev->d_sense, - key, asc, ascq); + scst_set_sense(cmd->sense, SCST_SENSE_BUFFERSIZE, + scst_get_cmd_dev_d_sense(cmd), key, asc, ascq); TRACE_BUFFER("Sense set", cmd->sense, SCST_SENSE_BUFFERSIZE); out: