From patchwork Wed Mar 20 13:37:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhengui li X-Patchwork-Id: 10861745 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 C23BE15AC for ; Wed, 20 Mar 2019 13:39:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8FE2299AD for ; Wed, 20 Mar 2019 13:39:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 925EE29BA5; Wed, 20 Mar 2019 13:39:32 +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 3B33A28A34 for ; Wed, 20 Mar 2019 13:39:31 +0000 (UTC) Received: from localhost ([127.0.0.1]:48130 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6bRK-0002oT-2k for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Mar 2019 09:39:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50339) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6bQL-0002Ch-3p for qemu-devel@nongnu.org; Wed, 20 Mar 2019 09:38:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h6bQJ-0008Ty-FC for qemu-devel@nongnu.org; Wed, 20 Mar 2019 09:38:29 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:59144 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h6bQD-0008Gh-Ff; Wed, 20 Mar 2019 09:38:23 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id C5A3D956D9A42D1157C5; Wed, 20 Mar 2019 21:38:13 +0800 (CST) Received: from HGHY1l002846723.china.huawei.com (10.177.251.193) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.408.0; Wed, 20 Mar 2019 21:38:05 +0800 From: Zhengui li To: , , , Date: Wed, 20 Mar 2019 21:37:08 +0800 Message-ID: <1553089028-21628-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 --- 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; }