File tgt-handle-access-of-a-target-that-has-been-removed of Package tgt

From: Lee Duncan <lduncan@suse.com>
Date: Wed, 28 Oct 2015 14:16:13 +0900
Subject: Handle access of a target that has been removed
Git-commit: 2791ed243ab2a2fcfe48aea4a0cc23f4ad8467dc
Patch-mainline: v1.0.61

I recently got a report of a tgtd core dump from our opencloud
group. The stack trace showed that a strcmp against a NULL was causing
the failure:

----------------------------------------------------------------
Program terminated with signal 11, Segmentation fault.
(gdb) bt
    name=0x6ac16f "iqn.2010-10.org.openstack:volume-e812c705-80bc-4064-a84c-5559cda8b1ca") at iscsi/target.c:216
    at iscsi/iscsid.c:654
    events=1, data=0x63a480 <target_list>) at iscsi/iscsi_tcp.c:158
----------------------------------------------------------------

It looks like target_find_by_name() uses tgt_targetname(), but doesn't
account for the fact that it can return a NULL when the target being
looked up does not (now) exist:

----------------------------------------------------------------
char *tgt_targetname(int tid)
{
	struct target *target;

	target = target_lookup(tid);
	if (!target)
	   return NULL;

	   return target->name;
}

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Acked-by: Lee Duncan <lduncan@suse.com>
---
 usr/iscsi/target.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--- a/usr/iscsi/target.c
+++ b/usr/iscsi/target.c
@@ -369,9 +369,11 @@ void target_list_build(struct iscsi_conn
 struct iscsi_target *target_find_by_name(const char *name)
 {
 	struct iscsi_target *target;
+	char *tname;
 
 	list_for_each_entry(target, &iscsi_targets_list, tlist) {
-		if (!strcmp(tgt_targetname(target->tid), name))
+		tname = tgt_targetname(target->tid);
+		if (tname && !strcmp(tname, name))
 			return target;
 	}
 
openSUSE Build Service is sponsored by