From patchwork Mon Sep 25 14:48:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 726036 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2437009wrm; Mon, 25 Sep 2023 08:00:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEzdterwLiF2nkcDYqJ5vRR63yPMstBH1o1Z8bIcgDCqTkuIX5VlIXIliKbv02BhBYGtjcc X-Received: by 2002:a05:622a:11d6:b0:417:b545:9eb5 with SMTP id n22-20020a05622a11d600b00417b5459eb5mr9247632qtk.10.1695654056448; Mon, 25 Sep 2023 08:00:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695654056; cv=none; d=google.com; s=arc-20160816; b=Vumrzo3y0ssn9dJESZKWWWQXZ/Dehz0QqkG3I1klgTDBYMXSi1OnFsoN1IpyrCDo8Y s1HznQKdo9eLnFWnB2Gwc0D8HuHS6USSknkG1+tR4U+vPtnBqwW886LlWn+ssY8uR+Sn Q3blGyj8hHzEjuAeyo8w24os5zJY/R3SMhqXY342IWsKpWpO7qbR5h7Jq5zq65Vu85Hz WYsQ3l2Gpmdd+XbqIJIPYjEr0FSImtYioixFCdgdlpqyDLgmrkiYaPlQRC/s3X2ci2Fm 3g7viodRVCSO6c9ySOtu5PQP8Fnmr0bcv5tz4E5BjOnvVEz4617YcAJLWtxw3l8VTkUx mhWg== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mAyYQkrKbWdgjPeSFpAKf8LHOxPMb7ttiO+d+H3EETQ=; fh=f1HG4YWa+ndoxgBhrv2wvoi5B5rsQCa0P0+M/9TAKns=; b=xw4/XLyjDsz5ecpEd1P/S7hrJLbwNOQyfo/5hG6CDCtUFQUZfmGwLZmnHa06b32SfV pFKgV+LFSPI1GN3YyECukn835qvNdUcdsj0B8K90yNKO0b6XBe/gM4Nl+NEP1ZzIFRWS 6Aug/WylrrsWxZ9pDkJbXRmeo+esSfLVYjyQT4Q28qkS7fJUPBRCtZULUmTTM0DITkLP 6CWUhwkjtQ0qodIdtS9V5hxgp1YzA5YWe74gVxWBVXVr5N0J4mOXYjSYM4NN2Lahv4cU parKnvJ5x6gQfLDCqLN0QYS20MrU6DxEOK4viZ5eE39PKC+eOsBTVV1r/ngumFLEX53y looQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eRiMNCpr; 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 e21-20020ac85995000000b00417f199f9e5si4167634qte.738.2023.09.25.08.00.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Sep 2023 08:00:56 -0700 (PDT) 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=eRiMNCpr; 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 1qkn3M-0000EE-BA; Mon, 25 Sep 2023 10:59:16 -0400 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 1qkn35-0008Kd-7u for qemu-devel@nongnu.org; Mon, 25 Sep 2023 10:59:00 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkn2q-0002DB-Bf for qemu-devel@nongnu.org; Mon, 25 Sep 2023 10:58:50 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-405524e6769so26305985e9.1 for ; Mon, 25 Sep 2023 07:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695653922; x=1696258722; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mAyYQkrKbWdgjPeSFpAKf8LHOxPMb7ttiO+d+H3EETQ=; b=eRiMNCprFqO+yGRM9oCTiA6Y0gwO4jqNb9dDsE33sA3iQFEIFTtvIUJYpYntOgaWXI 1ou0z6vyjLg4xYJj5rhzA0oCbCLvu1xmyJ7jH3L8DnrreZKVPe+9vP4VttZthz9gz3Oz CXsOL31lp/vEdZtQelIC4q2LRmsfP+xC56w/HsvqhM2xLXlbsl/gbkNhMOzW1RpWb7n8 FQdYPfdLoOMHlaiviU04i3ZgJ74Andxm+QmRYvaLNVBcVPrmmnH8sVyqRscRcZu9DokJ UixhJvqs/E4KTi8f3BioxfE3fk2GFp9hEJZv55+VxlxMD5Jo93v2LB2ofKulLk+Ff5rZ KkxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695653922; x=1696258722; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mAyYQkrKbWdgjPeSFpAKf8LHOxPMb7ttiO+d+H3EETQ=; b=h1DsiSKCJ5aXNCq5fv7SreNzcIQNpPx64a5RBr5FiTSNy35McARJkboDQPDITf9mW4 VnP/neNGSeSQZqlIp70SWWCh2iSlhnx8h+xsU+x8FY7rM1Q7GQ3OBEBSvHqC/PyT3JLy 2uWc0AdM+0BS0Sv/Vz8Nou5xHOlrLovdTsR9IkeBIIA6urMD/lVtEK2DH6/xakAPGnun +BVpYB8DKc7yvHy7VS5FBDxl0ktB3vsp8ZbCN2DzAnvXe+lkbgYNzeQRGSPCoOR2TfSv QugNCa6GIDOTj9tYdWJy/sJg6MPevnqeCK2LoXhSXXMPScb1yc4bJtPEnDVkAcxT8ccP AcBA== X-Gm-Message-State: AOJu0Yz9BdUgqIERhapUcWij0+mpPoMzJJW+FPSZmVElXIKPP3IRCW2+ 0QZlUjZUkX9YE9yHDuKfGW6u6w== X-Received: by 2002:a05:600c:1d8c:b0:405:d70d:1790 with SMTP id p12-20020a05600c1d8c00b00405d70d1790mr196064wms.13.1695653922594; Mon, 25 Sep 2023 07:58:42 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id t18-20020a1c7712000000b00405959469afsm1656915wmi.3.2023.09.25.07.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 07:58:41 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 139401FFCE; Mon, 25 Sep 2023 15:48:58 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Alistair Francis , =?utf-8?q?C=C3=A9dric_Le_Go?= =?utf-8?q?ater?= , Marcin Juszkiewicz , John Snow , libvir-list@redhat.com, =?utf-8?q?Marc-Andr?= =?utf-8?q?=C3=A9_Lureau?= , qemu-s390x@nongnu.org, Song Gao , Daniel Henrique Barboza , Marcel Apfelbaum , Bastian Koppelmann , Liu Zhiwei , Weiwei Li , Nicholas Piggin , Radoslaw Biernacki , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Cleber Rosa , Paolo Bonzini , Mahmoud Mandour , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Thomas Huth , Wainer dos Santos Moschetta , Richard Henderson , Bin Meng , Alexandre Iooss , Xiaojuan Yang , qemu-ppc@nongnu.org, David Hildenbrand , =?utf-8?q?Alex_Benn=C3=A9e?= , Yanan Wang , Peter Maydell , qemu-riscv@nongnu.org, qemu-arm@nongnu.org, Palmer Dabbelt , Ilya Leoshkevich , Laurent Vivier , Yoshinori Sato , Leif Lindholm , Beraldo Leal Subject: [PATCH 25/31] contrib/plugins: fix coverity warning in lockstep Date: Mon, 25 Sep 2023 15:48:48 +0100 Message-Id: <20230925144854.1872513-26-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925144854.1872513-1-alex.bennee@linaro.org> References: <20230925144854.1872513-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32a.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 Coverity complains that e don't check for a truncation when copying in the path. Bail if we can't copy the whole path into sockaddr. Fixes: CID 1519045 Fixes: CID 1519046 Signed-off-by: Alex Bennée --- contrib/plugins/lockstep.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/contrib/plugins/lockstep.c b/contrib/plugins/lockstep.c index 682b11feb2..f0cb8792c6 100644 --- a/contrib/plugins/lockstep.c +++ b/contrib/plugins/lockstep.c @@ -245,6 +245,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) static bool setup_socket(const char *path) { struct sockaddr_un sockaddr; + const gsize pathlen = sizeof(sockaddr.sun_path) - 1; int fd; fd = socket(AF_UNIX, SOCK_STREAM, 0); @@ -254,7 +255,11 @@ static bool setup_socket(const char *path) } sockaddr.sun_family = AF_UNIX; - g_strlcpy(sockaddr.sun_path, path, sizeof(sockaddr.sun_path) - 1); + if (g_strlcpy(sockaddr.sun_path, path, pathlen) >= pathlen) { + perror("bad path"); + return false; + } + if (bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) { perror("bind socket"); close(fd); @@ -287,6 +292,7 @@ static bool connect_socket(const char *path) { int fd; struct sockaddr_un sockaddr; + const gsize pathlen = sizeof(sockaddr.sun_path) - 1; fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) { @@ -295,7 +301,10 @@ static bool connect_socket(const char *path) } sockaddr.sun_family = AF_UNIX; - g_strlcpy(sockaddr.sun_path, path, sizeof(sockaddr.sun_path) - 1); + if (g_strlcpy(sockaddr.sun_path, path, pathlen) >= pathlen) { + perror("bad path"); + return false; + } if (connect(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) { perror("failed to connect");