From patchwork Wed Mar 20 14:07:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhengui li X-Patchwork-Id: 10861775 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E87B15AC for ; Wed, 20 Mar 2019 14:08:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05C1328D18 for ; Wed, 20 Mar 2019 14:08:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01CAA29CB4; Wed, 20 Mar 2019 14:08:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BEF2B29CB6 for ; Wed, 20 Mar 2019 14:08:52 +0000 (UTC) Received: from localhost ([127.0.0.1]:48482 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6btj-0004aS-Ql for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Mar 2019 10:08:51 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6bt7-0004IQ-P3 for qemu-devel@nongnu.org; Wed, 20 Mar 2019 10:08:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h6bt5-000742-Qy for qemu-devel@nongnu.org; Wed, 20 Mar 2019 10:08:13 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:59432 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h6bt1-0006sr-Q2; Wed, 20 Mar 2019 10:08:08 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 0050AC0896ECEA56EC58; Wed, 20 Mar 2019 22:08:02 +0800 (CST) Received: from HGHY1l002846723.china.huawei.com (10.177.251.193) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.408.0; Wed, 20 Mar 2019 22:07:55 +0800 From: Zhengui li To: , , , Date: Wed, 20 Mar 2019 22:07:27 +0800 Message-ID: <1553090847-11300-1-git-send-email-lizhengui@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.177.251.193] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.249.212.35 Subject: [Qemu-devel] [PATCH] qemu-pr-helper: check the return value of fcntl in do_pr_out X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wangjie88@huawei.com, lizhengui@huawei.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, eric.fangyi@huawei.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Stefano Garzarella Reviewed-by: Stefano Garzarella --- scsi/qemu-pr-helper.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index e7af637..fcbe4d9 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -551,8 +551,14 @@ 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; }