Skip to contentSkip to conversation

iscsi: Fix check for username

PATCH Applied Stefan Weil 3 participants 3 messages Mar 7, 2015 – Mar 9, 2015 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iscsi: Fix check for username

The variable user in struct iscsi_url is a character array, not a pointer. Therefore its address will never be NULL.

clang reports this error:

block/iscsi.c:1329:20: warning:
comparison of array 'iscsi_url->user' not equal to a null pointer is always true [-Wtautological-pointer-compare]

---

This error also exists in libscsi. See my pull request
https://github.com/sahlberg/libiscsi/pull/146

Cheers
Stefan

 block/iscsi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/iscsi.c +1 -1
index 1fa855a..a2bd70a 100644
@@ -1326,7 +1326,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
         goto out;
     }
 
-    if (iscsi_url->user != NULL) {
+    if (iscsi_url->user[0] != '\0') {
         ret = iscsi_set_initiator_username_pwd(iscsi, iscsi_url->user,
                                               iscsi_url->passwd);
         if (ret != 0) {
Signature · 1 line
2.1.4
Reviewed-by Acked-by on v1 1/1
#1 lore raw

Am 07.03.2015 um 10:14 schrieb Stefan Weil:

Quoted 26 lines

The variable user in struct iscsi_url is a character array, not a pointer. Therefore its address will never be NULL.

clang reports this error:

block/iscsi.c:1329:20: warning:
comparison of array 'iscsi_url->user' not equal to a null pointer is always true [-Wtautological-pointer-compare]

---

This error also exists in libscsi. See my pull request
https://github.com/sahlberg/libiscsi/pull/146

Cheers
Stefan

 block/iscsi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/iscsi.c +0 -0
index 1fa855a..a2bd70a 100644

block/iscsi.c static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, · line 1332

Quoted 8 lines
block/iscsi.c +1 -1
@@ -1326,7 +1326,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
         goto out;
     }
 
-    if (iscsi_url->user != NULL) {
+    if (iscsi_url->user[0] != '\0') {
         ret = iscsi_set_initiator_username_pwd(iscsi, iscsi_url->user,
                                               iscsi_url->passwd);
         if (ret != 0) {

Thanks for catching this. Luckily this call is before the parse_chap function. Otherwise it would have been impossible to specify username and password via config file.

#2 lore raw
In reply to Stefan Weil
Quoted 27 lines · Stefan Weil

The variable user in struct iscsi_url is a character array, not a pointer. Therefore its address will never be NULL.

clang reports this error:

block/iscsi.c:1329:20: warning:
comparison of array 'iscsi_url->user' not equal to a null pointer is always true [-Wtautological-pointer-compare]

---

This error also exists in libscsi. See my pull request
https://github.com/sahlberg/libiscsi/pull/146

Cheers
Stefan

 block/iscsi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/iscsi.c +0 -0
index 1fa855a..a2bd70a 100644

block/iscsi.c static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, · line 1332

Quoted 8 lines
block/iscsi.c +1 -1
@@ -1326,7 +1326,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
         goto out;
     }
 
-    if (iscsi_url->user != NULL) {
+    if (iscsi_url->user[0] != '\0') {
         ret = iscsi_set_initiator_username_pwd(iscsi, iscsi_url->user,
                                               iscsi_url->passwd);
         if (ret != 0) {

Applied, thanks.

Paolo