From 57d7bcd809615b0c70d654f08dfb3fbd3f61f635 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 4 Oct 2012 18:34:25 +0000 Subject: [PATCH] Fix 2 bugs in iscsi_attr_replace() sent by Lev Vainblat : 1. After attr was found in the attrs_list, it is inserted again back into the same list. As a result the list becomes corrupted. The bug can be reproduced for example by the following sequence: $ echo add_attribute IncomingUser user secret111111 > /sys/kernel/scst_tgt/targets/iscsi/mgmt $ echo user secret222222 > /sys/kernel/scst_tgt/targets/iscsi/IncomingUser $ echo del_attribute IncomingUser user > /sys/kernel/scst_tgt/targets/iscsi/mgmt $ iscsiadm -m discovery -t st -p 127.0.0.1 Discovery fails and in syslog there is a message Oct 2 18:58:37 vsa-00000611 iscsi-scstd: [1059] cmnd_exec_login:940: ERROR: Authentication of initiator iqn.2011-04.com.zadarastorage:1553:vc-0 failed 2. Small memory leak in error recovery path. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4545 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/config.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/iscsi-scst/usr/config.c b/iscsi-scst/usr/config.c index d795ddc46..39cc3e794 100644 --- a/iscsi-scst/usr/config.c +++ b/iscsi-scst/usr/config.c @@ -195,8 +195,6 @@ int iscsi_attr_replace(struct __qelem *attrs_list, const char *sysfs_name, a = iscsi_attr_lookup_by_key(attrs_list, key); - list_add_tail(attr, attrs_list); - if ((a != NULL) && (a != attr)) { log_error("Attr %s (sysfs_name %s) already exists\n", key, a->sysfs_name); @@ -216,6 +214,7 @@ int iscsi_attr_replace(struct __qelem *attrs_list, const char *sysfs_name, if (new_val == NULL) { log_error("Unable to duplicate attr_value %s", val); res = -ENOMEM; + free(new_key); goto out; } } else