From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id DC76E3858D1E for ; Fri, 15 Dec 2023 16:24:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DC76E3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DC76E3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702657447; cv=none; b=WPtfwtTebSKmUrseL0zGnFTe5lxc+aWsi0J0/AQEznu1XxKkg0gTkK29fo5onRc7A7U/FH+8oXrRYsvDuXJZJnPKP8K08afF4P2UqivNbgc6t9A+xJfu/N1msa21Qio17lB75REE9tmT4eSVRiSC4TCXmPFv6r4+//FJFlhp5KU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702657447; c=relaxed/simple; bh=mjkdakMBYyUZesZptcnuRZZwNeyf2CT6POnYkO/8bm4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=OCaLwn4PHcEb5VwzgVptlN3yQWVt2j3FCH5TOX1RzuooaRivSsXXVNZuFx0vSYhIx7WD3On50e8dnKB6TIh1hLwY8bN056w5seg2pNRKCh56g5e+NPuh31A/QmYGPBxTOGZFWgv8Eo5nzXyculF2Hnu9jBXK3z3DJoFGgTrpSjw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-35d72b72ff7so3370815ab.0 for ; Fri, 15 Dec 2023 08:24:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702657445; x=1703262245; darn=sourceware.org; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=Op3RGc1ACsLlKbrVuRzrwudy0p0Pgqp23KBVmDMHPOs=; b=DomZKszuHWLme4SmgXsZHHtX4jZdzElB8eyLBuYEXoKyjIkFfJPu4xm3EuK0jlzlQf IVM5DPpLNIQrroU4GWMWw0rAzh6LMBeqfpncoQXrNTLCX1FfBB1oUSY7G9ZGneON2R29 tHJB8LZMuMY5QWNKNNceBAOXh2KgV3/Wq3Kl4KI4LP8TalkdK2RjPEq0ec7c+9+Rbfz5 Kbwgq5LUdDqCFQkjRCDlOILZUAkodPL/VU/qoQBHjP4q0emCaA6oa8WGZOHq5uywbPQL rpwQVxWMQNrXZlTW3nuOvMBVpLsZGpFYEtnUD+36mclHmwOoZRAHF7RUYTHLwYabQaVQ olbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702657445; x=1703262245; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Op3RGc1ACsLlKbrVuRzrwudy0p0Pgqp23KBVmDMHPOs=; b=Kn0amj5SBosD21oMqSjrNwzWDp71R0xIdbV57R1XLHzc+URXe0rlM88k/Fouh7Auas nnE+ruyGxKfl1Bw5zfeWnW7jONifDBTLbYDGPZwDla87KjnwSl93NiLPzAUn0AgSJsay NzBJNUXFbiKpHIiFqnKYQtIq3M5tuDTgG5nHrumsgoK0MuRChGLYumB8uCPvekY5Hc4O 8s2oU5LfNHb+XfUQcUuaPRfTwoWF5BHp9faCW+EV6B2oBEVJgUUZjCpBAR/AG8TQrSmf DPEPWUXq39APfoCSEv/SjHFeNe6/AHTBWZcZZUGo5SQzoLDKgiFmacpN64+D2EKshAG8 PjbQ== X-Gm-Message-State: AOJu0Ywx64v3uaSEyuFV76IuJGI+qbPHV+j3v5l12yCIDIhF7EXEdx5V 3xCbBDwM2z+PLebosf03pFF35w== X-Google-Smtp-Source: AGHT+IHmlTOcnjf5aiH+00FZAdjfOgBtY0bcj8o5hytxOh+Epk+1hjSOEKF8ubSWQvHWWxEjLhPE8Q== X-Received: by 2002:a05:6e02:3399:b0:35f:8322:1b92 with SMTP id bn25-20020a056e02339900b0035f83221b92mr3733094ilb.24.1702657445005; Fri, 15 Dec 2023 08:24:05 -0800 (PST) Received: from murgatroyd (71-211-161-25.hlrn.qwest.net. [71.211.161.25]) by smtp.gmail.com with ESMTPSA id u4-20020a056e021a4400b0035d714a68fbsm4974804ilv.78.2023.12.15.08.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 08:24:04 -0800 (PST) From: Tom Tromey To: Simon Marchi Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [PATCH] Fix two bugs in gdbserver thread name handling References: <20231215145928.3396394-1-tromey@adacore.com> <63d99b56-ae76-4082-9074-1367506eed27@simark.ca> X-Attribution: Tom Date: Fri, 15 Dec 2023 09:24:03 -0700 In-Reply-To: <63d99b56-ae76-4082-9074-1367506eed27@simark.ca> (Simon Marchi's message of "Fri, 15 Dec 2023 10:53:19 -0500") Message-ID: <87sf4377to.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: Simon> My intuition is that the changes make sense, but it would be nice if you Simon> could describe the bugs in the commit message, to make sure we're on the Simon> same page. How's this? Tom commit 1d583fc640a2717b4e9d37d44602811ea201546f Author: Tom Tromey Date: Fri Dec 15 07:56:45 2023 -0700 Fix two bugs in gdbserver thread name handling Simon pointed out that my earlier patch to gdbserver's thread name code: commit 07b3255c3bae7126a0d679f957788560351eb236 Author: Tom Tromey Date: Thu Jul 13 17:28:48 2023 -0600 Filter invalid encodings from Linux thread names ... introduced a regression. This bug was that the iconv output was not \0-terminated. Looking at it, I found another bug as well -- replace_non_ascii would not \0-terminate, and also would return the wrong pointer This patch fixes both of them. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31153 diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index 4aa011c14ec..8cbc7833e53 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -7013,11 +7013,13 @@ current_lwp_ptid (void) } /* A helper function that copies NAME to DEST, replacing non-printable - characters with '?'. Returns DEST as a convenience. */ + characters with '?'. Returns the original DEST as a + convenience. */ static const char * replace_non_ascii (char *dest, const char *name) { + const char *result = dest; while (*name != '\0') { if (!ISPRINT (*name)) @@ -7026,7 +7028,8 @@ replace_non_ascii (char *dest, const char *name) *dest++ = *name; ++name; } - return dest; + *dest = '\0'; + return result; } const char * @@ -7064,8 +7067,8 @@ linux_process_target::thread_name (ptid_t thread) else if ((errno == EILSEQ || errno == EINVAL) && outbuf < &dest[sizeof (dest) - 2]) *outbuf++ = '?'; - *outbuf = '\0'; } + *outbuf = '\0'; iconv_close (handle); return *dest == '\0' ? nullptr : dest;