From patchwork Tue Mar 29 15:49:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610691 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=fMrEK+lP; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4KSYt549SHz9sFk for ; Wed, 30 Mar 2022 02:50:05 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYt53Rwlz2yHB for ; Wed, 30 Mar 2022 02:50:05 +1100 (AEDT) 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=fMrEK+lP; 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::629; helo=mail-pl1-x629.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=fMrEK+lP; dkim-atps=neutral Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) (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 4KSYt25bhrz2yMf for ; Wed, 30 Mar 2022 02:50:02 +1100 (AEDT) Received: by mail-pl1-x629.google.com with SMTP id i11so6715151plg.12 for ; Tue, 29 Mar 2022 08:50:02 -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=bceLJN7ktN9LqZd4Rgv2LwLHyETl4iqyA79zcOf++QM=; b=fMrEK+lPQVPcLn9opxAz2vGNdIwj4fi2oycEYnJ2F4LNZnrvMSM9vT7TjRTqXTdAx0 2gc/Xq6XbDX0YiRuYtenGk1Dyo/VUV2rPEIvhXn43ywS7E7oEgeYGxDnoa+sL2FP0y3Y 9kZxuTffXF3vbob438jpXwYp9QpPIahp+euZtoVbVX9ml12u6Sqvdh/0dUNpWQbXWlym W9ZMUP5U+c4bqIst7fzfHWYYHdmi3oOAjFftjiw4ZMNqWVopb91WUwTjMf0/hvLV4iBW WdwkdEL98K82jG3NnN3ylWvsnyNYnFPvEM7cUklbpWy/I4fY7EDIAHlCA+el2+/eMtCU ji+w== 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=bceLJN7ktN9LqZd4Rgv2LwLHyETl4iqyA79zcOf++QM=; b=nf9xdU1SbgH/aghJ662gsyl5acMsmIcSgODvXIde4x/ROn0VeLoMaRb6W2hgCkc0Lb VNj4seaqTjtTzQBwwP0FJKrx1j+X3d8iB56cJokIJ4yjzUJ+aoBZbDNeIAB+rQwoe3nJ qrBKkL9lvvVz1gQ4GH23/OYmFlMVQXMVct9TK6npBfX1uQ8hv0mIlvqke2GzGEfQBOBL lPzwE/LQL4gpqWoaVtlQ03gmaUJc7BLFosBT+gj/VON+rQ0vzpfFzn/6iB4LREME+F2f fz05RRIP/hGLGV7JwS7yvOc+A4ZoS+tzOWu1DIShqV2l07PA3yzsXYIcQ2CyXTk0PueN 8Stw== X-Gm-Message-State: AOAM532jzNJMUea1gKcNRR+0jp01Xv5zXPQCOKO6Cio9EhnRqzHO6qtx IqW9KeZACmzYHFYsSR3lGlRtcxpLQR0= X-Google-Smtp-Source: ABdhPJwmXbodo7f3EuOopGsSa0pTar08QLZh9Xs/Rij3ZM66Q4gVYuqSVsHVAADFq3h6rjbrV9J/qQ== X-Received: by 2002:a17:902:cec8:b0:154:6dd6:255d with SMTP id d8-20020a170902cec800b001546dd6255dmr31532265plg.62.1648569000529; Tue, 29 Mar 2022 08:50:00 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.49.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:00 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:02 +1000 Message-Id: <20220329154931.493851-10-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 09/38] 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 906ed2f..4c6327f 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;