From patchwork Wed Apr 20 06:49:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619336 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Z5UzCGmC; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kjrsl6vymz9sG0 for ; Wed, 20 Apr 2022 16:50:51 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrsl5mbRz2xrv for ; Wed, 20 Apr 2022 16:50:51 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Z5UzCGmC; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::62c; helo=mail-pl1-x62c.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Z5UzCGmC; dkim-atps=neutral Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Kjrsk1lvCz2yh9 for ; Wed, 20 Apr 2022 16:50:50 +1000 (AEST) Received: by mail-pl1-x62c.google.com with SMTP id be5so948799plb.13 for ; Tue, 19 Apr 2022 23:50:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=q6R2k03qZRslQHmGH6etoGS3YLQME/fO/cnU2wP/J54=; b=Z5UzCGmCRLJViJbwUztv4TEGK/NH/dKkCu9mdC+AxxFHF84qLdJIKGfeSNsMb9LOgz KadvgLAjKbMtmeKWd0Mk77O3vpJkNr9/gTjf0Ggw2MNIKjDPM7AjVrpOB3EL8SNmX0eM bl1gA6g5kTdMwJjQZSpBkZ3HIvUdMX9+2g/q4Jpijazfq4XrDq9RzGSr2ykwZTENY1BT kKJE2az+ogtTG2pAwaxeZVZc45RwI9PpzPqM2lhN5wu46uFwyVBRqq3mPruvkftJm41y ORp45enh15BjTrgOZn1ROKDpW1A8rv0U3qKEVUSXEGwE7QegD4SjfouNoGS7XUsBUmpD tf+g== 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=q6R2k03qZRslQHmGH6etoGS3YLQME/fO/cnU2wP/J54=; b=cQ2S810f+ph1MXOYNM3wjvyUZ/oXXVEWEubjp4s7bO+1mYdOLzGKVgWlzbWiv41D3y idwUBZx0zsrso4B3yHROaELXQif99Yun+XT9EE3gduKvq+WsrYhVBlVOOyXuCqrEG1Eu xkOkwFPePVDhECcQooZdDJaIlklsiRoYpjgyqHZ/hAMCRRJsRQbqyStqcxQ8aq9L7Tid lLwZlgB74ilJVcQXuFUPkWymcxXVRovhnTu378PLvkTG1NrNdzQRANhUA/30LTWCuR3v Ny67q/b781O5v+tOtCd8vZbSs1yBSqhm+ffLzzoM1YqlycPIdgk19pgG3eA3aSi1xyE2 126Q== X-Gm-Message-State: AOAM532CLm6NSEvW4+iVLEWOVT/X/iGxA66JdjBaMpx0FGx3GwR4TPdp njfGIQkqL7JGNBwQatYRyzFHiCpHmdnH1w== X-Google-Smtp-Source: ABdhPJy7/rElufGT0sw9qjyLa+Nr3116Xt1ZJPRsjGGvgUOQgUs7L2MKFxVAhD+OLUlgxcj7/EgDeA== X-Received: by 2002:a17:902:7407:b0:159:6a:8beb with SMTP id g7-20020a170902740700b00159006a8bebmr12883414pll.168.1650437447408; Tue, 19 Apr 2022 23:50:47 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.50.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:50:47 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:49:44 +1000 Message-Id: <20220420065013.222816-11-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 10/39] gdbserver: fix read buffer overflow X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" buffer gets NUL terminated so read must return max of size - 1. Reviewed-by: Joel Stanley Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 906ed2f6..4c6327fb 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -385,10 +385,10 @@ static void destroy_client(int dead_fd) static int read_from_client(int fd) { - char buffer[BUFFER_SIZE + 1]; + char buffer[BUFFER_SIZE]; int nbytes; - nbytes = read(fd, buffer, sizeof(buffer)); + nbytes = read(fd, buffer, sizeof(buffer) - 1); if (nbytes < 0) { perror(__FUNCTION__); return -1;