From patchwork Fri Nov 11 12:45:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 623733 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp748592pvb; Fri, 11 Nov 2022 04:46:09 -0800 (PST) X-Google-Smtp-Source: AA0mqf6AdQZKRcIbObJuFP/Pcxh1yt24XWdvB8YrCA8tOFGup5Q2vfqE/ev/PM+eKEoD80vemceJ X-Received: by 2002:ac8:6ec5:0:b0:3a5:82cf:faa5 with SMTP id f5-20020ac86ec5000000b003a582cffaa5mr1008529qtv.687.1668170769690; Fri, 11 Nov 2022 04:46:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668170769; cv=none; d=google.com; s=arc-20160816; b=MANCLksCA5cqRbDtr0F53EGLI/bVpE50GiRvFLgW9zU1xWxXDzOSjZuynqKFqm4kk7 9cHwNWdr9QMlhdfapsyDA+so9HdIoH40LMpXsF1MNyZNBdoxVuQ3iYq74g9iZ5sIpds6 5GLSh7Q6XFs0Qv+GfUwDmYYcy5yTYCDvtDePQeL65Ip7X/52yvJ4Jv4naCEzMLCMzz9Z XFizhxvSukLxEStrvb4u5hiUb4g0WsZRrfLuWHNzl7XXiqupA2cwn2KQkewe/K30RKef Xr0zfor4oKj2ex+BKkUnlV8oVYXFDhuManXL9Ua97WVMhdL5TMpt1uePC4408g0da81T 8XsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=11JiuZW9XczeUDUdrupJ37Xgv3YrtWkVOdT0bjn2y5Y=; b=f+oF2exOnD/Xgmp/PNjHHCftV9WtU5n584UHlab/hiGZlgxguBZDl7JNUXgAzWhczF wQno3gLM4dR5/fHwg8pr0N5v0eVMAoJ1vv/w1btLUcT0Y9J7MXYIdPVhC570C9umxJjx EDKVHSfVD4Hri5wDyYmlMW9Dmzxs0h2QS08/8iX7yr4gHhPUjVWrWhXvKYY8IiDK+1wP VD7byLHhIvPx1A/Jn7ylN/BuzG7r6FUp7XePPkhhIqr7BMkpbGAe33KbZJtDh6+2jMq2 Dk9gb3qLPfmu5NM8qOb6BeGxKD3hn2271ir50WOUTXpNEpBVEelDHqJk1khVXSxWw49G 3kwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P9SOla0j; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x20-20020a05620a0b5400b006fa0c24056bsi878962qkg.382.2022.11.11.04.46.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Nov 2022 04:46:09 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P9SOla0j; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otTPz-0005md-Tp; Fri, 11 Nov 2022 07:45:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otTPx-0005lb-9l for qemu-devel@nongnu.org; Fri, 11 Nov 2022 07:45:58 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otTPu-0001l5-NU for qemu-devel@nongnu.org; Fri, 11 Nov 2022 07:45:56 -0500 Received: by mail-wm1-x32f.google.com with SMTP id ja4-20020a05600c556400b003cf6e77f89cso5660048wmb.0 for ; Fri, 11 Nov 2022 04:45:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=11JiuZW9XczeUDUdrupJ37Xgv3YrtWkVOdT0bjn2y5Y=; b=P9SOla0jd7LsuZf8fkyQJP+cyJqwtaLEGxoydVSKrfVbHxgjq5+JdIg2WLRUkxlycA khjTYPNV9CpX3Lr8O92gn32sYMhKEo/QObM59lk2W59TGU6O5g6Yy6q1lLfdLwO91U+B 159ZR//fIcpmyDGLcpnTZWatrP83j9x0BPjCSw5Jrff9q0oZ59PMHeDwi97nU5rLG0NW zRawREgIABz6vDHphGGaWlLBqc8Djyvj5uNB7eT/JEXVhFaFpjXxNibtjlQAvATJgX9M Rg1FBKPe2/MAuuRBB4QaTZ41v9MvWJFChBKomtQlxDWCMBlLmkRvCc4WssRvP1XXE4QD UHtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=11JiuZW9XczeUDUdrupJ37Xgv3YrtWkVOdT0bjn2y5Y=; b=QZwJonbWDfkNXC4UTtQYBDiFHjce4mP6C37TOh5yaJZW/5B6+4Ro+w389GhnjYUeQl M0OXUTZgSB6oAF41cY9LbztCxAm5OIhCPhUrWSgM8OdvaG3p328jqytKI4gnBRvflVHj FIJ/zA9OjMul3eGwCIZc0Y5XZQ1vshEe1t9FrhCNg2RB0OJGdtmO9eVhhy8e44fqbtD+ gK3GHCuQk0o/TqkoCDVnCYBzCLlmDIo3D5JZENQG/ovio6aA4bZxOOrNpTaOo2I/ap4Z FVKUhfyWHolihe5RN1hBNQRGBnsvdiVxZjRnrnzc9U9vZ9CbMbBR8kIJQTxcUAnhTD8J ExQA== X-Gm-Message-State: ANoB5pnGxBigmAL3+zhSIsNjsX3cx/gkts2NnBmGQ49qtwzTXTrFaZlH vgwt5kEf5wo5iHVpLU3F41xsUVAEcdtn1x63cUA= X-Received: by 2002:a05:600c:295:b0:3cf:a457:2d89 with SMTP id 21-20020a05600c029500b003cfa4572d89mr1138651wmk.20.1668170752768; Fri, 11 Nov 2022 04:45:52 -0800 (PST) Received: from localhost.localdomain (ec2-54-194-108-71.eu-west-1.compute.amazonaws.com. [54.194.108.71]) by smtp.gmail.com with ESMTPSA id i11-20020a05600c354b00b003b4ff30e566sm3391659wmq.3.2022.11.11.04.45.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 11 Nov 2022 04:45:52 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Xie Yongji , Stefan Hajnoczi , Bin Meng , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Markus Armbruster , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Kevin Wolf Subject: [PATCH-for-7.2 v2] libvduse: Avoid warning about dangerous use of strncpy() Date: Fri, 11 Nov 2022 13:45:50 +0100 Message-Id: <20221111124550.35753-1-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=philmd@linaro.org; helo=mail-wm1-x32f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé GCC 8 added a -Wstringop-truncation warning: The -Wstringop-truncation warning added in GCC 8.0 via r254630 for bug 81117 is specifically intended to highlight likely unintended uses of the strncpy function that truncate the terminating NUL character from the source string. Here the next line indeed unconditionally zeroes the last byte, but 1/ the buffer has been calloc'd, so we don't need to add an extra byte, and 2/ we called vduse_name_is_invalid() which checked the string length, so we can simply call strcpy(). This fixes when using gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0: [42/666] Compiling C object subprojects/libvduse/libvduse.a.p/libvduse.c.o FAILED: subprojects/libvduse/libvduse.a.p/libvduse.c.o cc -m64 -mcx16 -Isubprojects/libvduse/libvduse.a.p -Isubprojects/libvduse -I../../subprojects/libvduse [...] -o subprojects/libvduse/libvduse.a.p/libvduse.c.o -c ../../subprojects/libvduse/libvduse.c In file included from /usr/include/string.h:495, from ../../subprojects/libvduse/libvduse.c:24: In function ‘strncpy’, inlined from ‘vduse_dev_create’ at ../../subprojects/libvduse/libvduse.c:1312:5: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound 256 equals destination size [-Werror=stringop-truncation] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors ninja: build stopped: cannot make progress due to previous errors. Fixes: d9cf16c0be ("libvduse: Replace strcpy() with strncpy()") Suggested-by: Markus Armbruster Signed-off-by: Philippe Mathieu-Daudé Tested-by: Bin Meng Reviewed-by: Stefan Hajnoczi Reviewed-by: Xie Yongji --- Supersedes: <20220919192306.52729-1-f4bug@amsat.org> Cc: Xie Yongji Cc: Kevin Wolf --- 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 1a5981445c..e089d4d546 100644 --- a/subprojects/libvduse/libvduse.c +++ b/subprojects/libvduse/libvduse.c @@ -1309,8 +1309,8 @@ VduseDev *vduse_dev_create(const char *name, uint32_t device_id, goto err_dev; } - strncpy(dev_config->name, name, VDUSE_NAME_MAX); - dev_config->name[VDUSE_NAME_MAX - 1] = '\0'; + assert(!vduse_name_is_invalid(name)); + strcpy(dev_config->name, name); dev_config->device_id = device_id; dev_config->vendor_id = vendor_id; dev_config->features = features;