From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E740F3935DC5 for ; Wed, 5 Jun 2024 13:15:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E740F3935DC5 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E740F3935DC5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717593332; cv=none; b=IWb+CyNSY7zPW37A8ezdWuXF0NWI6ZP0VUgWKfJkuCF6mcqQoRrBQBPNB0BdrG5I8a9QRRhbXAVfcd8bV1glY5rk/PoQtrW+TF33tCJ7S3QWjIvillMgPxzFSGObiem5I6T2rJafcyVKkf6uEtYJg/PCbE/ypWvFYO7ploYQDpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717593332; c=relaxed/simple; bh=+j6NQ+iLm8oquzuQzRj9B7BcweSbRgN2zXsHRI4D9j8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=mWakGuR3dQsrlTCcpNrgPcL3MuM/FAY4mShkamYsll1RldQWkV+CWPkEG2dGa4cPKNW6eFUzIG1biyfS/PU7MzTUGrem1Vj+tuP97FhCkT7gL2Ut213Hw+SrXpYW+zbWyA5ZwPYDtx4wH2XucJP+9a2SoFArXvIsC7JpdForyuw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717593328; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pr+/B8PhghJEWPxeOa63tRfmKBq+aObwPgFO0TeXqZY=; b=V6KakPGKYQIVG2wpcB1sh+L1aGt2viqMlf4yj5e341QXMiaCO6I49n3a+Er1+LMT3mxt5D 6AgJx+73XkK9eSDgGnt6tCPK18IONdI6GiuwrrYh7rUell3frWs/VclnBiIYdUqq587cyM FyYTQvfx62OSaMNeYXscMk1sO4C1mms= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-636-gvY6DcaJMDGR2L_GHPkmHw-1; Wed, 05 Jun 2024 09:15:23 -0400 X-MC-Unique: gvY6DcaJMDGR2L_GHPkmHw-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4215a04220eso1690845e9.3 for ; Wed, 05 Jun 2024 06:15:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717593321; x=1718198121; 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=pr+/B8PhghJEWPxeOa63tRfmKBq+aObwPgFO0TeXqZY=; b=qaC8rtZ6kc43gY77Scd/yiS+76vteRIXbMvmLLXskixQ4MoFwqz/3Z8c3dbXUqlKzC 3bSG2OkAnTj5g3zRoDBuyorQvJhpnKrLRXo2hLV8JX3+Vi/+yuN1gggaMTr+VfXrRi1a W2D7eawcp4L+0DtJeONmRrcipph0kWSgbTIqVhEcKWEzpp1aoLPWnpKVWKzq3Sdpi1fg 5qJ2i3KOuVS/KYNc3VVXrHvCjSgzT9WRMgzhoIOpcsqmIBgfTgC8E8HfOY4oho5m4QwZ mvx98wonanN5IGTxJv3oPeLaBvp8sFEj+DAE/xbmwjqEhhUdWjakdHusMAxmakc4y8jv I/Gg== X-Gm-Message-State: AOJu0YxnttlSp2D1dGvYbKrcznA6q03KxL9n07mGbr9ieH1BioKdkoU+ +FC7I72lsjf8L2/GE7zmammXSUmt0TbIIEEYPmBnIaBMpHDWWWrMGGS+xDZzwKW+XddahQRKxzD C7/RDLgLg4o52O5aaU80LYRp2nirHaDYiNXJXr48iDeW86fI0VYOhKkYfrFM3Ize1RKK38/5y4u p66rq9GRtDYcNqiQ4HJnzJXXUZBREd/y7u/zSJDrpaLvU= X-Received: by 2002:a5d:43cc:0:b0:354:fd10:d217 with SMTP id ffacd0b85a97d-35e98098fc8mr2139022f8f.63.1717593320944; Wed, 05 Jun 2024 06:15:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IER1kIWnevOprzHGlay1uEPbEGWxZeUSJU/73aTSqXrAoelAbihodQnG8Nci01wedx9DwDC5w== X-Received: by 2002:a5d:43cc:0:b0:354:fd10:d217 with SMTP id ffacd0b85a97d-35e98098fc8mr2138991f8f.63.1717593320309; Wed, 05 Jun 2024 06:15:20 -0700 (PDT) Received: from localhost ([31.111.84.186]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35dd064affasm14515918f8f.106.2024.06.05.06.15.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 06:15:19 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/8] gdb/fileio: fix errno for packets where an attachment is expected Date: Wed, 5 Jun 2024 14:15:08 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: In remote.c lives remote_target::remote_hostio_send_command(), which is used to handle sending a fileio packet to the remote, and for parsing the reply packet. Some commands, e.g. open, pwrite, close, send some arguments to the remote, and then get back a single integer return value. Other commands though, e.g. pread, readlink, fstat, send some arguments and get back an integer return value and some additional data. This additional data is called the attachment. Except, we only get the attachment if the command completes successfully. For example, calling readlink with a non existent path will result in a return packet: 'F-1,2' with no attachment. This is as expected. Within remote_hostio_send_command we call remote_hostio_parse_result, this parses the status code (-1 in our example above) and then parses the errno value (2 in our example above). Back in remote_hostio_parse_result we then hit this block: /* Make sure we saw an attachment if and only if we expected one. */ if ((attachment_tmp == NULL && attachment != NULL) || (attachment_tmp != NULL && attachment == NULL)) { *remote_errno = FILEIO_EINVAL; return -1; } Which ensures that commands that expect an attachment, got an attachment. The problem is, we'll only get an attachment if the command succeeded. If it didn't, then there is no attachment, and that is as expected. As remote_hostio_parse_result always sets the returned error number to FILEIO_SUCCESS unless the packet contained an actual error number (e.g. 2 in our example above), I suggest we should return early if remote_hostio_parse_result indicates an error packet. I ran into this issue while working on another patch. In that patch I was checking the error code returned by a remote readlink call and spotted that when I passed an invalid path I got EINVAL instead of ENOENT. This patch fixes this issue. Unfortunately the patch I was working on evolved, and my need to check the error code went away, and so, right now, I have no way to reveal this bug. But I think this is an obviously correct fix, and worth merging even without a test. --- gdb/remote.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gdb/remote.c b/gdb/remote.c index 349bc8cf005..241803ab2b3 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -12663,6 +12663,9 @@ remote_target::remote_hostio_send_command (int command_bytes, int which_packet, return -1; } + if (*remote_errno != FILEIO_SUCCESS) + return -1; + /* Make sure we saw an attachment if and only if we expected one. */ if ((attachment_tmp == NULL && attachment != NULL) || (attachment_tmp != NULL && attachment == NULL)) -- 2.25.4