System call open() might return -1 if an error occurred which
should be taken into consideration.

Signed-off-by: Wenchao Hao <haowenc...@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqian...@huawei.com>
Signed-off-by: Wu Bo <wub...@huawei.com>
---
 utils/iscsi-iname.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/utils/iscsi-iname.c b/utils/iscsi-iname.c
index 0f587e1..834352e 100644
--- a/utils/iscsi-iname.c
+++ b/utils/iscsi-iname.c
@@ -96,7 +96,8 @@ main(int argc, char *argv[])
         * uniqueness properties
         */
 
-       if ((fd = open(RANDOM_NUM_GENERATOR, O_RDONLY))) {
+       fd = open(RANDOM_NUM_GENERATOR, O_RDONLY);
+       if (fd != -1) {
                e = read(fd, &entropy, 16);
                if (e >= 1)
                        MD5Update(&context, (md5byte *)entropy, e);
@@ -141,7 +142,8 @@ main(int argc, char *argv[])
         * good as any other).
         */
 
-       if ((fd = open(RANDOM_NUM_GENERATOR, O_RDONLY))) {
+       fd = open(RANDOM_NUM_GENERATOR, O_RDONLY);
+       if (fd != -1) {
                if (read(fd, entropy, 1) == 1)
                        bytes = &digest[(entropy[0] % (sizeof(digest) - 6))];
                close(fd);
-- 
2.27.0

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to open-iscsi+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/open-iscsi/20201207015410.48488-3-haowenchao%40huawei.com.

Reply via email to