[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] qemu-pr-helper: check the return value of fcntl in
From: |
Zhengui li |
Subject: |
[Qemu-devel] [PATCH] qemu-pr-helper: check the return value of fcntl in do_pr_out |
Date: |
Wed, 20 Mar 2019 21:37:08 +0800 |
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 <address@hidden>
---
scsi/qemu-pr-helper.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
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;
}
--
2.7.2.windows.1
- [Qemu-devel] [PATCH] qemu-pr-helper: check the return value of fcntl in do_pr_out,
Zhengui li <=