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 74ACF3856DF1 for ; Tue, 18 Jul 2023 13:03:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 74ACF3856DF1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689685416; 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=9oQtOL3xYZ4NGlJkkJLZk23pBRXve2G/OoXwrDM4VNE=; b=NvTkRVhIs8+/27aXKG2ZQjwmX9KHIdtPLh9X8tWVOWq9cLXNZaSkABuVczGZEtxFXNlLzi HFO6p+xr7EF7BAFekye3f4J00HdcCyY/6rut34PpD/TbEHL3rsbS8r3gSaGd7JmEK+IuLD g6aBSI7Nqggbvh+3JrWNNBzoMLAkmjg= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-260-4sYWsPflMQOogPUZ9eF4QA-1; Tue, 18 Jul 2023 09:03:35 -0400 X-MC-Unique: 4sYWsPflMQOogPUZ9eF4QA-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7673e4eee45so509705085a.0 for ; Tue, 18 Jul 2023 06:03:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689685410; x=1692277410; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9oQtOL3xYZ4NGlJkkJLZk23pBRXve2G/OoXwrDM4VNE=; b=b2NfhvMKrR9Wu5T3ziUPbFFdfzXTkTpNnpcfhqqyJokIYtGJSnsOdT6gqkYFa+HqQP uQnpoptJD7nHja5fzczzln9wjc7mDfR+ff2OcklEir/Vf5vj+BWcLhZP7yVUKHcvtWox 8SB9iDL/ntg1iLgGy313AkT3rI79OiFTJehURcvvsKj2UVDf7aElIDH48VL8X/aJ7i9p wnHebVw67c3JPA/qKvTDKUToADtw14uisO7AXJPAB4u6KMYsdVYUmob9LfdQ2VoVgiL/ mDh8kgXOjefW/bPfjpgpcT/DkFMVTtyFnh2II6Gn0c++qWIOSJpK5V0lG3fuGPVYpBbH DFZg== X-Gm-Message-State: ABy/qLZHRuOEaVLplLrEj1zUN7UGPEy63vtxbR2MXvFqMQD73bfgfFt1 K0rfADNz8bK4Q7QjvNJUcsgSlOnEu5W3SaN/q8nQvffL+E7R52yYQJ9+JejKORctaETae31bbzx xECWuDEBk/lWCVyug9CgX84iugP4Jlw== X-Received: by 2002:a0c:aa8d:0:b0:635:ed4c:50e with SMTP id f13-20020a0caa8d000000b00635ed4c050emr9296376qvb.15.1689685409907; Tue, 18 Jul 2023 06:03:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlGscSEs8BrwTqRK/GF9bpXGNh2mCOZZLgEF9fb9CZm3AZ1ChKZ2gYUg6vdDF/gYWt+rXhbOug== X-Received: by 2002:a0c:aa8d:0:b0:635:ed4c:50e with SMTP id f13-20020a0caa8d000000b00635ed4c050emr9296313qvb.15.1689685409090; Tue, 18 Jul 2023 06:03:29 -0700 (PDT) Received: from [192.168.0.129] (ip-94-112-225-44.bb.vodafone.cz. [94.112.225.44]) by smtp.gmail.com with ESMTPSA id r15-20020ac85e8f000000b00403cce833eesm629975qtx.27.2023.07.18.06.03.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Jul 2023 06:03:28 -0700 (PDT) Message-ID: Date: Tue, 18 Jul 2023 15:03:26 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH] gdb: Fix "target file /proc/.../cmdline contained unexpected null characters" To: Ilya Leoshkevich , Tom Tromey Cc: gdb-patches@sourceware.org References: <20230621231425.3972673-1-iii@linux.ibm.com> From: Bruno Larsen In-Reply-To: <20230621231425.3972673-1-iii@linux.ibm.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_BARRACUDACENTRAL,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: On 22/06/2023 01:14, Ilya Leoshkevich via Gdb-patches wrote: > cmdline is read with target_fileio_read_stralloc(), which warns on > seeing null characters. However, it's perfectly valid for cmdline to > contain \0s, so switch to target_fileio_read_alloc(). Hi! Thanks for working on this. From what I understand, GDB commit messages should be written so that they make sense even if you don't read the title, so having a slightly more descriptive message would be nice. > --- > gdb/linux-tdep.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c > index b5eee5e108c..96cbe8e5520 100644 > --- a/gdb/linux-tdep.c > +++ b/gdb/linux-tdep.c > @@ -1902,15 +1902,22 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) > pid = inferior_ptid.pid (); > xsnprintf (filename, sizeof (filename), "/proc/%d/cmdline", (int) pid); > /* The full name of the program which generated the corefile. */ > - gdb::unique_xmalloc_ptr fname > - = target_fileio_read_stralloc (NULL, filename); > + gdb_byte *buf = NULL; > + size_t buf_len = target_fileio_read_alloc (NULL, filename, &buf); > + gdb::unique_xmalloc_ptr fname ((char *)buf); > Looking at the code on linux_info_proc, I see that this approach is already used, so it looks like a good idea to me. However, in there, the string is slightly sanitized, so that '\0' in the middle of the string are turned into ' ', and the final character is always set to '\0'. I think you could probably do the same here. > - if (fname == NULL || fname.get ()[0] == '\0') > + if (buf_len < 1 || fname.get ()[0] == '\0') > { > /* No program name was read, so we won't be able to retrieve more > information about the process. */ > return 0; > } > + if (fname.get ()[buf_len - 1] != '\0') If you don't do the same, at least here the last character should be changed. Its pretty dangerous to allow it to pass since like 5 lines later this is used as a C-string, so you could get read-past-the-end and other nasty problems. -- Cheers, Bruno > + { > + warning (_("target file %s " > + "does not contain a trailing null character"), > + filename); > + } > > memset (p, 0, sizeof (*p)); >