From patchwork Mon Oct 9 16:41:03 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: 731025 Delivered-To: patch@linaro.org Received: by 2002:a5d:574c:0:b0:31d:da82:a3b4 with SMTP id q12csp1313625wrw; Mon, 9 Oct 2023 09:49:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEF7ihMFL24Kkg/ftQUd3Nv315wrzIGgJhtZ6gljuylMxWKaDLZycxAq8Br+zMGv/0wbemv X-Received: by 2002:a05:6870:f141:b0:1c8:ca70:dd0c with SMTP id l1-20020a056870f14100b001c8ca70dd0cmr17357042oac.19.1696870141515; Mon, 09 Oct 2023 09:49:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696870141; cv=none; d=google.com; s=arc-20160816; b=D7NfxNryGC66Bdpt8vESii9xvobYO185UEyyv+jcVE/GXYNVcJkARzy9BPCHhbGZ17 qNJNeY6qABLJNf+FQExg8AO02OASLn4RtcddA+5KGW2073z/UMeH9w458CZKRnkD46rW g36MWKnpKp/f/75PjokQRHffqX3NyTrtwQSdcnLWCMJxf5Q8x0mzq+pG4KeZ/lM15PQA Y9eu3CTnzrxvDERQK6wO8KxAMjAakpGP3GcGRl8QnE2Le38kvdW83wZ3I5e1nhZbK7/S HYsarwCAjPcEolGqvS+eR/sMSQr6vGdwe8klkZCIG1AUYCHbnbSNB5GUVSsHLj+kcLoR dNnQ== 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=hH+hY2AOPCtQWK44NzX0H5SWS0EYJFmL3o+I0zvKKVU=; b=m7eoFxViSdcdf/MmDhZM0IxsgsK2z+mYn21YT9M40ik1Mc3WCOb+NBJasOIoYviUog GLkHTteK9oDYQ33nRquaqp5he0MNjZse3rRItyEOsf44XSt3l9qyO559YroXM1rIwcKM j8faqVVHCr9O+V8DhhaBj78QwMQLlipB2RBRqSDSc8nk1iDxC+UM+H759q4YI6PAb0jt 4xVsEGCGuiavtaGsMpRG70R9xHARl4OyrbdEd3faJmKO0St3l1lHXvZC1Wt+CUMWL/3I qQ69iyWDbJBHejKNcf6BeP9leQwXH69WkKQuXl2rDhbgmG+Pmc+KyY+pYMEcYpzm7Tmy hPOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J5Lr0jcl; 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 q18-20020a0cf5d2000000b0065881095c04si6312619qvm.407.2023.10.09.09.49.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Oct 2023 09:49:01 -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=J5Lr0jcl; 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 1qptPZ-0005Ne-NZ; Mon, 09 Oct 2023 12:47:17 -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 1qptPC-0003JD-PP for qemu-devel@nongnu.org; Mon, 09 Oct 2023 12:46:59 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qptOl-0003Xa-Dj for qemu-devel@nongnu.org; Mon, 09 Oct 2023 12:46:50 -0400 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3296b49c546so2831952f8f.3 for ; Mon, 09 Oct 2023 09:46:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696869975; x=1697474775; 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=J5Lr0jclW7J339kIM66DlxNeLzBa14n1qo/PBMaOl7bsS/yXRn5HTmqlsmNAxv3W3X zJsN4TNXJpddqyAfjfSlhP6HeWThSqZpTrrCZX2ucIrOqGMsnaui8L8/DA4yA0Vu/r9P M6bksoVSx8CYFS3zgaXaV44EJZ5fY+Dp9agVP9UZNuEwmNwqI2x2p+msvC0luwHe3igG VQ1xjqLT4txAGAbGuo+onm7vGMcMdx3VyJa97gRaxtJnfTCYXEtBl6p4VBYXekTzMF5Q jf3gqth3dkBEqlt2239J1f8K8RwIUnFFZsvAQrv2HeKFcxaLwqkcY7cZRzDrYp230fRg eexw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696869975; x=1697474775; 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=rPCCLZjrKUTLPwIc5Be6xMAqhrSzQNOiMRtHAOjxhOGvxJbTHJEfwQ27z1t1ykGOko Pgtj5TEqhaxSqOA0jTDB0M1ZMaoKaavMucLUQcqixnykCA01fNi2DIa7XpjJ5C4kNj8G 2dmpuxtOsgPFHBVHuzjvZGO6vmMBczXoVkrOem09DVL836svomBmEYrkZO6pLGgVl1Sr mYpELJw1tzKOeYQ67hpUYL6eJXuVFUnf9c2/Azs1FVakLajchg3vIIfQoRmcMxVaxQ17 QPk4PlyejHWWzP72A2FqfV+RG4xoQCx57Gjn802lSrO6JwHPU3yN3WNy6CBdScxFMnYw hG4g== X-Gm-Message-State: AOJu0Yz7TyhiNVr3JmyY6KUfLO/UgSwcoIXIEhUCfFjmIgyYN5zU1FXc TDzcNhCFOj77NAztY38Vd7oNcQ== X-Received: by 2002:adf:b34a:0:b0:329:6c6a:c733 with SMTP id k10-20020adfb34a000000b003296c6ac733mr7480553wrd.58.1696869974897; Mon, 09 Oct 2023 09:46:14 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id t11-20020a5d534b000000b003232380ffd5sm10082444wrv.106.2023.10.09.09.46.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 09:46:13 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id ED3E71FFCF; Mon, 9 Oct 2023 17:41:07 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Thomas Huth , Xiaojuan Yang , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Alex_Benn=C3=A9?= =?utf-8?q?e?= , Bastian Koppelmann , Brad Smith , Radoslaw Biernacki , David Hildenbrand , Cleber Rosa , Ilya Leoshkevich , qemu-riscv@nongnu.org, Daniel Henrique Barboza , Alexandre Iooss , Nicholas Piggin , Bin Meng , Leif Lindholm , Paolo Bonzini , Eduardo Habkost , Alistair Francis , qemu-ppc@nongnu.org, John Snow , Liu Zhiwei , qemu-arm@nongnu.org, Wainer dos Santos Moschetta , Palmer Dabbelt , Peter Maydell , Yanan Wang , Weiwei Li , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Marcel Apfelbaum , Beraldo Leal , Yoshinori Sato , Mahmoud Mandour , Richard Henderson , Song Gao , Marcin Juszkiewicz , qemu-s390x@nongnu.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 24/25] contrib/plugins: fix coverity warning in lockstep Date: Mon, 9 Oct 2023 17:41:03 +0100 Message-Id: <20231009164104.369749-25-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231009164104.369749-1-alex.bennee@linaro.org> References: <20231009164104.369749-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42e.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=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+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");