From patchwork Wed Oct 11 10:33:28 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: 731957 Delivered-To: patch@linaro.org Received: by 2002:a5d:54d1:0:b0:31d:da82:a3b4 with SMTP id x17csp330103wrv; Wed, 11 Oct 2023 03:45:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEKAGOBbZK2gnRZuRltAdnFbNrjYrGNvFtEBBjhY7Ig9XUcxcea1p5XfvTlIeFP2Mz2XNbf X-Received: by 2002:a05:620a:2847:b0:775:7fee:7913 with SMTP id h7-20020a05620a284700b007757fee7913mr23629148qkp.16.1697021133923; Wed, 11 Oct 2023 03:45:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697021133; cv=none; d=google.com; s=arc-20160816; b=0DatgOXHLa870Bq5w3TnmfF+5vBQFEUQr3fNCrQTofC81ku3LK1nfQ3kONlW0xWXMe BVOCQGMsSPAamngVzMAFN09vVtPnrPTLuaAnwNU8y5Lt7VoM+AX2X9esmaBrLTaGQOEe WaQBPK1q7sThCKOrVTFKogX5nBdoxKmtcGFnOKqlJU0ycZmAJty7sYz1Jt0x+JLMtoh7 ZBpOKTJaPNmsRxgsqYBg/WV+mjaBDl31sivBwXt7nrCKHJSGVt6DrV6OMhbB6DsbO0Ze pfBj7XW+Sm70F7LAntZoKLQHbpD/GxAPpNbHdbnu3zlrwpZq3MwOt8op1TCGfRwxxhHp RWfA== 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=UzxurWFBanGJDGa17SzO9nkXVLYIxRz6NOFY5btFFbY=; fh=kyaHiEU+lIVT4poymSOoM0p0KZxXkvLW2auuM3J5H08=; b=tQ1OgIlktbu6CqqpedsZJx+2aQeMBWHVoKFfJ7N9jxW4dKh+7BEx+0/h+GDVzBl1ZF 1tL0yBEEtP+apFsWiLZB3xBWHAxXGeSCg9NIySoJtOMpBM5U9VLiqdOYruJZ6t91yq65 Au/WZn63fPCEKA9ZKEsJLONJRgmn/kHgLXUkG8NCvPGJa86B4/qvMmblk+m1NPKTMYDK BGQiB617/k824Vdv8wTS8LRVKRXF0Ou9r9sKd4dN1lRHRcU3SZeHuBCMMiRSr7nEvCy0 u1yBitwlKRIDW+hknLvv7FMVG4nLf/Ed6jXU8OsoVN9Ch23silM0EnqR6e3p0NctXgde DhWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YMm7N0b0; 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 v6-20020a05620a0f0600b007749dc7ce1bsi9222209qkl.752.2023.10.11.03.45.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Oct 2023 03:45:33 -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=YMm7N0b0; 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 1qqWgn-0008Ez-JM; Wed, 11 Oct 2023 06:43:41 -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 1qqWgk-0008CS-WD for qemu-devel@nongnu.org; Wed, 11 Oct 2023 06:43:39 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qqWgi-0007fE-8m for qemu-devel@nongnu.org; Wed, 11 Oct 2023 06:43:38 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-32483535e51so6424182f8f.0 for ; Wed, 11 Oct 2023 03:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697021013; x=1697625813; 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=UzxurWFBanGJDGa17SzO9nkXVLYIxRz6NOFY5btFFbY=; b=YMm7N0b0Y/Wip/32VNVUBE58AJWrlJ8nRx9elgJIqICF/tYRqs4pjWN5aa9O6gDWOn yeGdUdMqt3K51vWvjf88ZAjwTKrXoEqOqHWSsE54BwHBnMiuKd1G/7+bLVLZaSwBVZi5 nrV1EZzdbNkyRfIuEoO5h+1RI8770wivX3vuLcX7AD9IoQ9GGk8MOhd9xiEfcBLErr0R n567WyjCuHf+TpACqQw0tYrHAYc4sRBF0z6IlPizyvNeIkQprgMps+Id3VZOQuJuxTER 6o+Y8d++8MDsLDCdMuS1LJN9XWqAMkdcfSCLGjbjZOl+vyKES9NXapRRCV7e8M6UghQK jk/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697021013; x=1697625813; 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=UzxurWFBanGJDGa17SzO9nkXVLYIxRz6NOFY5btFFbY=; b=qUNVyFxbslaUdbjRCJE2ZAZ83nMFiJrOT86hI1rMaGjfeMt7BddCkzEXtYbFJsT67V g94ExVN4Yd18LJ1UU0Qfj2Tzi6p4DWeculSjfQtZgQRs7EWMeG7SfzyYgY1kGPsfRGxa YqKBdmt15ullUM948IPiKE0810TDbIzOVfotYzeRzz6B41yABAgpxnLY6UeUnrRZs5fy cttdiGFRKBPLIY0lwh2/XlxQLPElsdIlJ0w3Od+n6DDMK0VXeWnXt0pVHcy4zGraiPvG Qpy3i6clEHptzDkPkQZ2B0DqxqhSfGCqfd1sVeiPx4EXSnGz9yUudzlGk2A6QVvF/eqX Eq+A== X-Gm-Message-State: AOJu0Yz4RIZKRH14eIhamKy6v94w3XKUeNfiX4gJukBq5IelJrD0aa2k 9F/DMmcQFCtgBY3LIOWB8py46g== X-Received: by 2002:adf:e607:0:b0:31f:b9ea:76c with SMTP id p7-20020adfe607000000b0031fb9ea076cmr17169987wrm.48.1697021012784; Wed, 11 Oct 2023 03:43:32 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id p4-20020a5d68c4000000b003232f167df5sm15134109wrw.108.2023.10.11.03.43.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 03:43:31 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B950A1FFCF; Wed, 11 Oct 2023 11:33:32 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 24/25] contrib/plugins: fix coverity warning in lockstep Date: Wed, 11 Oct 2023 11:33:28 +0100 Message-Id: <20231011103329.670525-25-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011103329.670525-1-alex.bennee@linaro.org> References: <20231011103329.670525-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x430.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 Message-Id: <20231009164104.369749-25-alex.bennee@linaro.org> 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");