From nobody Mon Aug 11 20:52:54 2025 X-Original-To: bugs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4c16KL4HBTz64xNP for ; Mon, 11 Aug 2025 20:52:54 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4c16KL25v4z3p4b for ; Mon, 11 Aug 2025 20:52:54 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754945574; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZJes20SrKr+eut0prw1MeUcbhRn9cGuYAIgIwQ9/nHs=; b=o5SyZij4/cQU9hmPRDaHehYl/GR38jl/GWQBDxmuj1aap+y3MRU6WcPuew2CNpmjBsb0Cq ljK2C/jYmzcaMY5eSOsgQGodqI7xLR52AQyO/QQB5sPUXB9uk41+yByLuvY6c3khtjsWqm 232Nbt4zA3GUCzOwIMXn8KxFbG2XHLq1KaCv2GVU36UPjWZD3ETCFy535B3BFlDLQox7S4 pK85ssuVzMNGnBrN1CKf+s7O5ZIRNV08mlNdCfd8H4S+WV5+kdTwKbpZpWscIZhd3/rVQm NVvIE3NUi7bbjHAnBNRPi7bwPtF6Pb+A4LaOQNAvu+n372uIU9DqhTwhR5x58A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754945574; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZJes20SrKr+eut0prw1MeUcbhRn9cGuYAIgIwQ9/nHs=; b=dPhUFkO5jI/7P1TTfvVrGi0scblqqALYs+VrX6SXsnHctUPyeiFDll3EVBap8b+OBON5or Z6jFIapnyhQNs6kQOLlqhYeKBSUKjbkYNeLXi+IraxG0DqvBsSHKbE4QfNwTEqwoANibYS 4iTbiVg+O0Y9q2eNtEidiloRoBBoJ1csurG1pjkm89lZ8EbNGPbKyGdPYE23ejwd1qhg6R qWJX9atme7AeNBH0VSH4v7HGz1woFNXm+pLiQpsuIPvsQoFyYVrnB4PCU3wHdy/bHPv/RD mykHC4HNbQKUOABLnZMeSuNofcsKR5Lsxfppe3UZJUAD5mpRM0iQZBH/5hemoA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1754945574; a=rsa-sha256; cv=none; b=ZmiVXk1EPODHTni1ZHxb6ZY5hE0xRRnxCCW7cFP6gJMBpjFLPgc8xXYHSFtxIS2smmRQBS 9CpPfvwWQ7v5Akb6kiMBW30z0jsumpPHF1f5aaArEizJaQsanVNKAgdcGcM7kDha2BQlC/ zo0+Tl2eAh2Zq6pZSTZPWK1GZC20MkypF1/RU7KBXTOANpUqepL9eNLaM7As3mV9Ws2FdV xmA7HZmljdYY7JphBWP71bclei8gLJ+xWkgkCpwz4Uh+6b+4yvSQvCe6ZZG/1u4HUiR24C 1aNzk5Axso/Z6U0wR1/WL7P/zGPwAYLK8rUMmMObpQNnm6pdKR+oV/j/nrY3zg== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4c16KL1k3Zz17Jv for ; Mon, 11 Aug 2025 20:52:54 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 57BKqsQX034544 for ; Mon, 11 Aug 2025 20:52:54 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 57BKqs0v034543 for bugs@FreeBSD.org; Mon, 11 Aug 2025 20:52:54 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 288805] [libcxxrt] __cxa_demangle() implementation does not adhere to Itanium C++ ABI Date: Mon, 11 Aug 2025 20:52:54 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: 14.3-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: freebsd-bugzilla@mhxnet.de X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@FreeBSD.org MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D288805 Bug ID: 288805 Summary: [libcxxrt] __cxa_demangle() implementation does not adhere to Itanium C++ ABI Product: Base System Version: 14.3-RELEASE Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: bin Assignee: bugs@FreeBSD.org Reporter: freebsd-bugzilla@mhxnet.de I've previously reported this on Github for lack of a bugzilla account: https://github.com/libcxxrt/libcxxrt/issues/50 I've noticed this on FreeBSD, but reporting it here as I can't seem to be a= ble to create a bugzilla account. The Itanium C++ ABI [states](https://itanium-cxx-abi.github.io/cxx-abi/abi.html#demangler) that ``` namespace abi { extern "C" char* __cxa_demangle (const char* mangled_name, char* buf, size_t* n, int* status); } ``` - If `buf` is a null pointer, `__cxa_demangle` allocates a new buffer with `malloc`. It stores the size of the buffer in `*n`, if `n` is not `NULL`. - If `buf` is not a null pointer, it must have been allocated with `malloc`= . If `buf` is not big enough to store the resulting demangled name, `__cxa_deman= gle` must either a) call `free` to deallocate `buf` and then allocate a new buff= er with `malloc`, or b) call `realloc` to increase the size of the buffer. In either case, the new buffer size will be stored in `*n`. The [current implementation](https://github.com/libcxxrt/libcxxrt/blob/a6f71cbc3a1e1b8b9= df241e081fa0ffdcde96249/src/typeinfo.cc#L88-L105) has two issues: - It stores the *length of the string* in `*n`, not the buffer size as required. - It *overwrites* `*n` unconditionally, regardless of whether or not a re-allocation happened. Here's [simple test case in compiler explorer](https://gcc.godbolt.org/z/PE9xzP8br). You can see that using `libstdc++`, `__cxa_demangle` behaves as expected: ``` buffer contents: int string length : 3 buffer size : 4 buffer contents: int string length : 3 buffer size : 21 ``` Building the same code on macOS (using `libc++` instead), the implementation also suffers from the second issue: ``` buffer contents: int string length : 3 buffer size : 4 buffer contents: int string length : 3 buffer size : 4 ``` FreeBSD currently suffers from both issues: ``` buffer contents: int string length : 3 buffer size : 3 buffer contents: int string length : 3 buffer size : 3 ``` This bug actually triggers [an assertion](https://github.com/facebook/folly/blob/main/folly/FBString.h#L31= 0) when using `folly::demangle`, as it calls an `fbstring` constructor that ta= kes ownership of the buffer and checks that the buffer size is large enough for= the string to hold a trailing `\0` terminator. --=20 You are receiving this mail because: You are the assignee for the bug.=