From patchwork Mon Jun 27 09:02:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 1648808 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bytedance-com.20210112.gappssmtp.com header.i=@bytedance-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=vEeoB6/J; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LWhbz2CC8z9sGm for ; Mon, 27 Jun 2022 19:03:59 +1000 (AEST) Received: from localhost ([::1]:58792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o5kew-00053n-60 for incoming@patchwork.ozlabs.org; Mon, 27 Jun 2022 05:03:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49640) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o5kdc-0004Py-QP for qemu-devel@nongnu.org; Mon, 27 Jun 2022 05:02:33 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:39852) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o5kdX-0006vf-PR for qemu-devel@nongnu.org; Mon, 27 Jun 2022 05:02:29 -0400 Received: by mail-pj1-x102e.google.com with SMTP id b12-20020a17090a6acc00b001ec2b181c98so11718591pjm.4 for ; Mon, 27 Jun 2022 02:02:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WB4U1grSmPbKhsyhD3ueGmnY+ms5NTRAoGVFPsY0gog=; b=vEeoB6/JiqyjiepGsJOHPrtLIau01QKECJl4XuZ6wLi1G61gJ9GX1SEfD6pakBhXGv BQXYAyca0HrOzj0TAU0E1Mau86q7i3Dc0Ew2NMscpZHdN8erhfh8aPB6Tei36gsV8HLH rdCe03A4+tcsHLoqyr53bwmcXYni32ZyVdjT00eDRH9VXy3LzV0W0lywmnCfr0oukE/J X4auIcx2PMPwr5O1P2UgaeW32pSekPK+FfD9Ltm0IdwOCvyA2/VxY3hErHjJ9tXdV5+I pTf9nr0c/kAAIIBWIYdZ8Yhvh57DhXwF21tnBo5KiDkdYMNJvj0b63OGj4oPDTjXTBWI 4qjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WB4U1grSmPbKhsyhD3ueGmnY+ms5NTRAoGVFPsY0gog=; b=zGeaxl1oUpiMR31eBAViyw5u470wCVoSpalpgBLc4WO/YpGl3uVAx4Oy9F47r+TUfC WFKvTPjrG55InTltzBWRBaxUHpdQP9rJETIRJpa5jvwpxJmK/QiEbH88WWa7+a9aSUmn eatwBd63xQjize6DYzjGX0+QktVKD4mCdy5+grVMKV9P9XT3a8Tos4wH9JYPs09jekM1 hO7Xbb4HCiLlfC/VJdgNW72ZhcwP1Ud3s1z5a/9bO/B4M1M7nKBOARuC1O6Rs1uWxjKz VlNkUZmVWhmxW9yn2YSybvUu46Sgamauwrs5YxILpZLaQypyAP1hn+XOQBktCcKSORKQ WKwg== X-Gm-Message-State: AJIora8RWazY5m1iD9PNZ3f/LJ2aB/LWHQh+JMVQkmeDE3l0akJbs1aa RtfUf0e6unzXGsqhEGiA1ulh X-Google-Smtp-Source: AGRyM1tFYuRtzfUSkg+mx4Z0hcjIhdghgHdn/BzvZj4Ur3Gfhgs1qOo+19GWZObXTSCASDNWQ/HJFA== X-Received: by 2002:a17:902:9046:b0:168:b8ee:8164 with SMTP id w6-20020a170902904600b00168b8ee8164mr13544571plz.159.1656320546270; Mon, 27 Jun 2022 02:02:26 -0700 (PDT) Received: from localhost ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id y9-20020a056a001c8900b005254535a2cfsm6615644pfw.136.2022.06.27.02.02.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 02:02:25 -0700 (PDT) From: Xie Yongji To: kwolf@redhat.com, stefanha@redhat.com, armbru@redhat.com Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 1/4] libvduse: Fix the incorrect function name Date: Mon, 27 Jun 2022 17:02:00 +0800 Message-Id: <20220627090203.87-2-xieyongji@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220627090203.87-1-xieyongji@bytedance.com> References: <20220627090203.87-1-xieyongji@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=xieyongji@bytedance.com; helo=mail-pj1-x102e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" In vduse_name_is_valid(), we actually check whether the name is invalid or not. So let's change the function name to vduse_name_is_invalid() to match the behavior. Signed-off-by: Xie Yongji Reviewed-by: Markus Armbruster --- subprojects/libvduse/libvduse.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/subprojects/libvduse/libvduse.c b/subprojects/libvduse/libvduse.c index 9a2bcec282..6374933881 100644 --- a/subprojects/libvduse/libvduse.c +++ b/subprojects/libvduse/libvduse.c @@ -1193,7 +1193,7 @@ static int vduse_dev_init(VduseDev *dev, const char *name, return 0; } -static inline bool vduse_name_is_valid(const char *name) +static inline bool vduse_name_is_invalid(const char *name) { return strlen(name) >= VDUSE_NAME_MAX || strstr(name, ".."); } @@ -1242,7 +1242,7 @@ VduseDev *vduse_dev_create_by_name(const char *name, uint16_t num_queues, VduseDev *dev; int ret; - if (!name || vduse_name_is_valid(name) || !ops || + if (!name || vduse_name_is_invalid(name) || !ops || !ops->enable_queue || !ops->disable_queue) { fprintf(stderr, "Invalid parameter for vduse\n"); return NULL; @@ -1276,7 +1276,7 @@ VduseDev *vduse_dev_create(const char *name, uint32_t device_id, struct vduse_dev_config *dev_config; size_t size = offsetof(struct vduse_dev_config, config); - if (!name || vduse_name_is_valid(name) || + if (!name || vduse_name_is_invalid(name) || !has_feature(features, VIRTIO_F_VERSION_1) || !config || !config_size || !ops || !ops->enable_queue || !ops->disable_queue) { fprintf(stderr, "Invalid parameter for vduse\n"); From patchwork Mon Jun 27 09:02:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 1648810 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bytedance-com.20210112.gappssmtp.com header.i=@bytedance-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=qEebbFYV; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LWhhp5pKDz9sGm for ; Mon, 27 Jun 2022 19:08:10 +1000 (AEST) Received: from localhost ([::1]:38438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o5kj2-0001uv-BD for incoming@patchwork.ozlabs.org; Mon, 27 Jun 2022 05:08:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o5kdd-0004SG-Gq for qemu-devel@nongnu.org; Mon, 27 Jun 2022 05:02:33 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:41773) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o5kdb-0006wM-Qh for qemu-devel@nongnu.org; Mon, 27 Jun 2022 05:02:32 -0400 Received: by mail-pl1-x631.google.com with SMTP id c4so7589501plc.8 for ; Mon, 27 Jun 2022 02:02:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=auTM1k9MJH1G+/UMXAU7lBSEiGjik9z9z+Wt3cqMDh8=; b=qEebbFYVVAb8Sm615bsm3hHmDCIv+f8pDZ91V66y4Gm4gMim4zTG0Z0SzXjgZq/GjB zTdNbQhOV3K0lqy1BYlmLtRa9/ZfnqV9XzsCqdLYLdz+//SpnL1EARzAJNDUhYXRPqS9 Ev0fWwjt3pd+09cJ56Odywl8JtZf8BsJpyBUIuSjpNhp7amnbVyVJzDEOvMc5qCEnhgX /8BKVtRXFzJ2e9haKv4e1fi2xzhgujzOv6VA9xkl+jtrFxc1uKITiPu6GQNtPOO62rG6 ayh/CDweb6Pqpgvc8Xl5UbAGWjmhYTCTTm7DxfYGXJDtPkMR5xN8phPjIU2NIr+oyZVq We+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=auTM1k9MJH1G+/UMXAU7lBSEiGjik9z9z+Wt3cqMDh8=; b=UiBtyW2/w0kv/tJiOwGwj7A2zpPKioVReEOh6UXhec/soLIgdTvLoKnFPKtvugkj6X /5D/MbFzQCcMqjp8V1T09YieCkeyqnuQ6DBKT6w/YbLViHZh637HFJwb5hXZUqr0VFrw vxIbbj0Hg6zY5ofMz0WU9HRf8iCl4Yo7gl/rqcfF9sKJUffp+meURVcTTzPLMAUqjy3G OaLdDpP2Egav0ulfHC2+8en4huYHq9l1SRJ7FUtiQtjUfo+PyNqDgrA5gUcTDyju6Mt8 TjWzRulFwfWuRaKNTZv241FTkhO6ZisOywsgEmTc4/tpQ4T6E2IpVuNKO23B/cq/JGIO 2aEg== X-Gm-Message-State: AJIora9CHDrSmOQIaVwPF1MvYQI8CpW4XwtFJS1ZR9y8Mm13R1tZlW7T +MPbfHl7WTIsLn6uL+KHwlFE X-Google-Smtp-Source: AGRyM1vvfrobmP9Et4vbVKZ1ZQ9ZGlXseXXOHpwHS/3clYBGPhQzgw1C0s+52E3eSYv7zqJR9mgyag== X-Received: by 2002:a17:90a:3e07:b0:1ed:492d:2792 with SMTP id j7-20020a17090a3e0700b001ed492d2792mr11663297pjc.57.1656320550330; Mon, 27 Jun 2022 02:02:30 -0700 (PDT) Received: from localhost ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id x9-20020a056a00188900b0050dc762818csm6760511pfh.102.2022.06.27.02.02.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 02:02:29 -0700 (PDT) From: Xie Yongji To: kwolf@redhat.com, stefanha@redhat.com, armbru@redhat.com Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 2/4] libvduse: Replace strcpy() with strncpy() Date: Mon, 27 Jun 2022 17:02:01 +0800 Message-Id: <20220627090203.87-3-xieyongji@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220627090203.87-1-xieyongji@bytedance.com> References: <20220627090203.87-1-xieyongji@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=xieyongji@bytedance.com; helo=mail-pl1-x631.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Coverity reported a string overflow issue since we copied "name" to "dev_config->name" without checking the length. This should be a false positive since we already checked the length of "name" in vduse_name_is_invalid(). But anyway, let's replace strcpy() with strncpy() to fix the coverity complaint. Fixes: Coverity CID 1490224 Signed-off-by: Xie Yongji Reviewed-by: Markus Armbruster --- subprojects/libvduse/libvduse.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subprojects/libvduse/libvduse.c b/subprojects/libvduse/libvduse.c index 6374933881..1e36227388 100644 --- a/subprojects/libvduse/libvduse.c +++ b/subprojects/libvduse/libvduse.c @@ -1309,7 +1309,8 @@ VduseDev *vduse_dev_create(const char *name, uint32_t device_id, goto err_dev; } - strcpy(dev_config->name, name); + strncpy(dev_config->name, name, VDUSE_NAME_MAX); + dev_config->name[VDUSE_NAME_MAX - 1] = '\0'; dev_config->device_id = device_id; dev_config->vendor_id = vendor_id; dev_config->features = features; From patchwork Mon Jun 27 09:02:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 1648812 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bytedance-com.20210112.gappssmtp.com header.i=@bytedance-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=wjd3IAYD; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LWhlg53vpz9sGm for ; Mon, 27 Jun 2022 19:10:39 +1000 (AEST) Received: from localhost ([::1]:45634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o5klR-0006wO-8q for incoming@patchwork.ozlabs.org; Mon, 27 Jun 2022 05:10:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o5kdn-0004Xl-4S for qemu-devel@nongnu.org; Mon, 27 Jun 2022 05:02:43 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:39680) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o5kdh-0006wr-8c for qemu-devel@nongnu.org; Mon, 27 Jun 2022 05:02:41 -0400 Received: by mail-pg1-x533.google.com with SMTP id q140so8521293pgq.6 for ; Mon, 27 Jun 2022 02:02:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lobGhQMyEP9xa06Ky0/LJmVgLT+aF3hayGVBWKrCnw4=; b=wjd3IAYDgsB0u6wh/aWTE7t8E+1V3btQ8Y4qRNSQh7h+MqxZQ0tbaY0995qm/Zvswc +0Wieqn/xKdF4FpiqKFIQscf5NBRrj21et0SzmyGRdyELWzWFgnzO1g0GGwtkrf7zU9i ZVZxCie4nxPjOpiOVWRZ+Pk9uR+Pexz173LlMhl4oiQUms2CM3cLCkA9nKYeE4fkqybK Z823jHx66zaSOw6glFg5DBFpKH3RiksglEoWo7MXGI1MjwxCQAF4ETqThAH5z65aYX9d 392HM2eLptMWaefU1XgUQjFIsEF/b+Oa+Jf6kmrItl/vPTkLqbyGG9sPtMy9hGzCcr+X H/3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lobGhQMyEP9xa06Ky0/LJmVgLT+aF3hayGVBWKrCnw4=; b=cQqLMCdo0EUX8VL17IfB/Z6BzF02VFoscpi3tC+b/LtUXl7tjFQgGH8aTJbAlWVmMI qzXgA42+w4/98DsnkhtOa9/C4i1dIj8VkQhiFwgJZ0HcF2HCtRwsT4s0NzOgPIvEVC4N rEnu5CY1uAWt1QoTSq7dSbwqbSSM+CF+SvCCQG3NpyObJ8BiWundgby3oJGIVNCExQym BqQ52MkHAfVqsIfx807dhTPY65V4r7yu7/999sA7eeB/wcC0BqVg5GJJTSqzm729CMO3 HWFul7OaNDiM13ug83fZmIU4jPBQ7DrIBR1P1P2jvhpZDZWF28jV7DjptG3y8BX1VcTp 6VdQ== X-Gm-Message-State: AJIora/Zr6Q5mTv6ReugkEUDTuUXKH7/2buKup0xXL79YSCQHw8IEx3J cUTZGQGvLfWn/vM7umv1ZZ+Y X-Google-Smtp-Source: AGRyM1ty72mEpqVjg6vP2AZOuRmm2oqeLsBaoI/4WZmNw2awhosn3Vu+Lx8mQRtQlzLzwJczp8Yj1w== X-Received: by 2002:a65:6e44:0:b0:3db:219e:2250 with SMTP id be4-20020a656e44000000b003db219e2250mr11621680pgb.369.1656320554342; Mon, 27 Jun 2022 02:02:34 -0700 (PDT) Received: from localhost ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id a14-20020a1709027d8e00b0016b7ba73a18sm1740654plm.38.2022.06.27.02.02.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 02:02:33 -0700 (PDT) From: Xie Yongji To: kwolf@redhat.com, stefanha@redhat.com, armbru@redhat.com Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 3/4] libvduse: Pass positive value to strerror() Date: Mon, 27 Jun 2022 17:02:02 +0800 Message-Id: <20220627090203.87-4-xieyongji@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220627090203.87-1-xieyongji@bytedance.com> References: <20220627090203.87-1-xieyongji@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=xieyongji@bytedance.com; helo=mail-pg1-x533.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The value passed to strerror() should be positive. So let's fix it. Fixes: Coverity CID 1490226, 1490223 Signed-off-by: Xie Yongji Reviewed-by: Richard Henderson Reviewed-by: Markus Armbruster --- subprojects/libvduse/libvduse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subprojects/libvduse/libvduse.c b/subprojects/libvduse/libvduse.c index 1e36227388..1a5981445c 100644 --- a/subprojects/libvduse/libvduse.c +++ b/subprojects/libvduse/libvduse.c @@ -1257,7 +1257,7 @@ VduseDev *vduse_dev_create_by_name(const char *name, uint16_t num_queues, ret = vduse_dev_init(dev, name, num_queues, ops, priv); if (ret < 0) { fprintf(stderr, "Failed to init vduse device %s: %s\n", - name, strerror(ret)); + name, strerror(-ret)); free(dev); return NULL; } @@ -1331,7 +1331,7 @@ VduseDev *vduse_dev_create(const char *name, uint32_t device_id, ret = vduse_dev_init(dev, name, num_queues, ops, priv); if (ret < 0) { fprintf(stderr, "Failed to init vduse device %s: %s\n", - name, strerror(ret)); + name, strerror(-ret)); goto err; } From patchwork Mon Jun 27 09:02:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 1648811 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bytedance-com.20210112.gappssmtp.com header.i=@bytedance-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=etDgIugD; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LWhj21qFrz9sGm for ; Mon, 27 Jun 2022 19:08:20 +1000 (AEST) Received: from localhost ([::1]:39044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o5kjB-0002L5-6Q for incoming@patchwork.ozlabs.org; Mon, 27 Jun 2022 05:08:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49774) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o5kdn-0004XX-2T for qemu-devel@nongnu.org; Mon, 27 Jun 2022 05:02:43 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:40817) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o5kdj-0006xC-TK for qemu-devel@nongnu.org; Mon, 27 Jun 2022 05:02:42 -0400 Received: by mail-pf1-x42c.google.com with SMTP id c205so8377321pfc.7 for ; Mon, 27 Jun 2022 02:02:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iI/8y2WKhVlI7+Tk5R1G7JW9URpKy+i2P2xkIFUTLj0=; b=etDgIugDx/Gfp2lViqplaJWfyyBxKfwUsA6nneR0d5r9cg3X4O7Wzf3+Gy8KqgR1Nf 7RbBypmhTHHCT1zERbS2Yzrdmjwh43Y8wz76krHgphq308ZgqJFsnYUf/+IA2/GVHobT 4fti0ebdDFd6S7CVkjay3HU4IrEDAJ6UVluNR0yTNxjXcF5WaFAEyVJ68TixHq9aRWPN 0vnV5fC2gU0mGCxLUcbjfvTQxGh3LvwORdWXxLN82NNx+OEurUaTqK8loPB7VCRUFX+d zbx6esxD4k6htImsL1sVm9VC2bLroiVswkk+d7jM7GrFqMC6gq+jGNMTcttAfRMIuelw L58A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iI/8y2WKhVlI7+Tk5R1G7JW9URpKy+i2P2xkIFUTLj0=; b=s2Q/VzcHgKclRaPRB2xY7ghFSSb6ciPtv96CXgDISLSjWSYz5wUWbNJ9xV3SpRig/r L81zYmVqFYM4P61AZ157H4/m6gSXDYp1ASe6pRMamI+2esDOPQHQ2HwLifJ+5hBqf4TI sND38fE/nIWytstV5qrNDr5sld83s8bUn790yl/0g+O6uo+SHP4mBzxQINcBQOawMIvJ /IPI6Q6jag6qy4nbwQMEbTeGfvoWvV8eDuII1sN+UgOkro9Y7C+O/xt/r92Skw+ZNW9C HJeiXoY/7HtIH9eIhsnRn5LKDhdPFqPMGk4xuPC6Xuq+F+59yZMwJk8d58L2+C1kTP3W F+HA== X-Gm-Message-State: AJIora/fcBkvmMLcSeX5peH0xK/emrzBiEBBgY9wdKb0YXzuoHx7X6aw X4mRJgdUmuCxNDdANG+AHiHd X-Google-Smtp-Source: AGRyM1vzq9XNv7pgNHrFODYL4R2d+h6cjq3ARcy9y+LK5cbynpGjjtXF/u2sNOAgr6VnbVQtfT6JUg== X-Received: by 2002:a63:6aca:0:b0:408:8af6:a885 with SMTP id f193-20020a636aca000000b004088af6a885mr11814291pgc.477.1656320558163; Mon, 27 Jun 2022 02:02:38 -0700 (PDT) Received: from localhost ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id 125-20020a630483000000b0040d2717473fsm6765403pge.38.2022.06.27.02.02.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 02:02:37 -0700 (PDT) From: Xie Yongji To: kwolf@redhat.com, stefanha@redhat.com, armbru@redhat.com Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 4/4] libvduse: Check the return value of some ioctls Date: Mon, 27 Jun 2022 17:02:03 +0800 Message-Id: <20220627090203.87-5-xieyongji@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220627090203.87-1-xieyongji@bytedance.com> References: <20220627090203.87-1-xieyongji@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=xieyongji@bytedance.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Coverity pointed out (CID 1490222, 1490227) that we called ioctl somewhere without checking the return value. This patch fixes these issues. Fixes: Coverity CID 1490222, 1490227 Signed-off-by: Xie Yongji --- subprojects/libvduse/libvduse.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/subprojects/libvduse/libvduse.c b/subprojects/libvduse/libvduse.c index 1a5981445c..bf7302c60a 100644 --- a/subprojects/libvduse/libvduse.c +++ b/subprojects/libvduse/libvduse.c @@ -947,7 +947,10 @@ static void vduse_queue_disable(VduseVirtq *vq) eventfd.index = vq->index; eventfd.fd = VDUSE_EVENTFD_DEASSIGN; - ioctl(dev->fd, VDUSE_VQ_SETUP_KICKFD, &eventfd); + if (ioctl(dev->fd, VDUSE_VQ_SETUP_KICKFD, &eventfd)) { + fprintf(stderr, "Failed to disable eventfd for vq[%d]: %s\n", + vq->index, strerror(errno)); + } close(vq->fd); assert(vq->inuse == 0); @@ -1337,7 +1340,10 @@ VduseDev *vduse_dev_create(const char *name, uint32_t device_id, return dev; err: - ioctl(ctrl_fd, VDUSE_DESTROY_DEV, name); + if (ioctl(ctrl_fd, VDUSE_DESTROY_DEV, name)) { + fprintf(stderr, "Failed to destroy vduse device %s: %s\n", + name, strerror(errno)); + } err_dev: close(ctrl_fd); err_ctrl: