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: 1059192 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44PWH43YBqz9sPL for ; Thu, 21 Mar 2019 00:39:10 +1100 (AEDT) Received: from localhost ([127.0.0.1]:48124 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6bQx-0002Ej-NG for incoming@patchwork.ozlabs.org; Wed, 20 Mar 2019 09:39:07 -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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; }