diff mbox series

qemu-pr-helper: check the return value of fcntl in do_pr_out

Message ID 1553089028-21628-1-git-send-email-lizhengui@huawei.com (mailing list archive)
State New, archived
Headers show
Series qemu-pr-helper: check the return value of fcntl in do_pr_out | expand

Commit Message

Zhengui li March 20, 2019, 1:37 p.m. UTC
The function fcntl maybe return -1, which is not a unsigned type. Unsigned type or Negative values should not do bitwise operator with O_ACCMODE.

Signed-off-by: Zhengui li <lizhengui@huawei.com>
---
 scsi/qemu-pr-helper.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

no-reply@patchew.org March 20, 2019, 1:42 p.m. UTC | #1
Patchew URL: https://patchew.org/QEMU/1553089028-21628-1-git-send-email-lizhengui@huawei.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 1553089028-21628-1-git-send-email-lizhengui@huawei.com
Subject: [Qemu-devel] [PATCH] qemu-pr-helper: check the return value of fcntl in do_pr_out

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

From https://github.com/patchew-project/qemu
 * [new tag]         patchew/1553089028-21628-1-git-send-email-lizhengui@huawei.com -> patchew/1553089028-21628-1-git-send-email-lizhengui@huawei.com
Switched to a new branch 'test'
5dcbf97 qemu-pr-helper: check the return value of fcntl in do_pr_out

=== OUTPUT BEGIN ===
ERROR: braces {} are necessary for all arms of this statement
#24: FILE: scsi/qemu-pr-helper.c:557:
+    if (flags < 0)
[...]

ERROR: trailing statements should be on next line
#27: FILE: scsi/qemu-pr-helper.c:560:
+    if ((unsigned int) flags & O_ACCMODE) == O_RDONLY) {

total: 2 errors, 0 warnings, 14 lines checked

Commit 5dcbf975925b (qemu-pr-helper: check the return value of fcntl in do_pr_out) has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/1553089028-21628-1-git-send-email-lizhengui@huawei.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
no-reply@patchew.org March 20, 2019, 1:46 p.m. UTC | #2
Patchew URL: https://patchew.org/QEMU/1553089028-21628-1-git-send-email-lizhengui@huawei.com/



Hi,

This series failed the asan build test. Please find the testing commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
time make docker-test-debug@fedora TARGET_LIST=x86_64-softmmu J=14 NETWORK=1
=== TEST SCRIPT END ===

  CC      hw/core/machine.o
  CC      hw/core/loader.o
  CC      hw/core/qdev-properties-system.o
/tmp/qemu-test/src/scsi/qemu-pr-helper.c:560:43: error: expected expression
    if ((unsigned int) flags & O_ACCMODE) == O_RDONLY) {
                                          ^
1 error generated.


The full log is available at
http://patchew.org/logs/1553089028-21628-1-git-send-email-lizhengui@huawei.com/testing.asan/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
diff mbox series

Patch

diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
index e7af637..da1f0f2 100644
--- a/scsi/qemu-pr-helper.c
+++ b/scsi/qemu-pr-helper.c
@@ -551,8 +551,13 @@  static int do_pr_out(int fd, const uint8_t *cdb, uint8_t *sense,
                      const uint8_t *param, int sz)
 {
     int resp_sz;
+    int flags;
 
-    if ((fcntl(fd, F_GETFL) & O_ACCMODE) == O_RDONLY) {
+    flags = fcntl(fd, F_GETFL);
+    if (flags < 0)
+        return -1;
+
+    if ((unsigned int) flags & O_ACCMODE) == O_RDONLY) {
         scsi_build_sense(sense, SENSE_CODE(INVALID_OPCODE));
         return CHECK_CONDITION;
     }