From patchwork Wed Jul 31 13:24:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1967111 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=asQXE4+N; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WYtC23MSwz1ybb for ; Wed, 31 Jul 2024 23:25:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 005403858424 for ; Wed, 31 Jul 2024 13:25:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 231903858C56 for ; Wed, 31 Jul 2024 13:25:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 231903858C56 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 231903858C56 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=1722432323; cv=none; b=vJCESC5ZYUzzJW7QdzAnw48e2CM6IRr6xHksmTtufUxwBffZL7e09Vew5SPoBJTvPOV/lKNaFnYu1/z16XP51wQuFB5nyQSp/RW5Tykm0YnJDJAtD0/P0PNW2o08+IgQwNywrc6PF5OnjD31UsmB0BSRCKWOTXPF+NfbnOJCsOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722432323; c=relaxed/simple; bh=Bv9+tKtx+BnK39Y8NhwcJ/c+fbYndBPhVMUyG5qXwhA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xNP9PDPtDrxnY9wX3UpfSf9mwNZxYB0hi881obbbt7lme6JZ/fLwInWpyM9Ncc7QL4mEfBdwFKEpLTFEX/2vJSkDGWfPiZA56bHUNTUkdAc7o8MY97vN6TPjPR+AZn+AczOT6CN1MqQ7vG3uMMO5c86/9aoOJcWL/rgdU6fmUfM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722432321; 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=H4pvO+ES+/TURfH1e7PJe77uvoCAexHNXgZB/5nGb54=; b=asQXE4+Nm/FT2odNandTH87a3l8mpgyWpC0sWflBTTqCwxWB7tlJbWYmgIc3xhw2j3eTml V1ScI4sAPUZmXPLsJ9AsK5rwmlcqo6gNkJW7BLIPGBOBAC0AsCZnDReXkfqAsJIuL1EWh2 6YMjlGcT4PgytmNSnd7T7iWDtayTk+0= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-400-QpfpDRY9P0aUPrJlAaJ3LQ-1; Wed, 31 Jul 2024 09:25:19 -0400 X-MC-Unique: QpfpDRY9P0aUPrJlAaJ3LQ-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BF658192DE18; Wed, 31 Jul 2024 13:25:17 +0000 (UTC) Received: from localhost (unknown [10.42.28.21]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B8FAA19560AA; Wed, 31 Jul 2024 13:25:15 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Alexandre Oliva Subject: [PATCH] libstdc++: Handle strerror returning null Date: Wed, 31 Jul 2024 14:24:15 +0100 Message-ID: <20240731132514.56823-1-jwakely@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org As discussed a couple of weeks ago, I'm going to push this. Tested x86_64-linux (where this #else isn't even used, but I checked it does at least compile when the #if isn't true). -- >8 -- The linux man page for strerror says that some systems return NULL for an unknown error number. That violates the C and POSIX standards, but we can esily handle it to avoid a segfault. libstdc++-v3/ChangeLog: * src/c++11/system_error.cc (strerror_string): Handle non-conforming NULL return from strerror. --- libstdc++-v3/src/c++11/system_error.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/src/c++11/system_error.cc b/libstdc++-v3/src/c++11/system_error.cc index d01451ba1ef..38bc0446110 100644 --- a/libstdc++-v3/src/c++11/system_error.cc +++ b/libstdc++-v3/src/c++11/system_error.cc @@ -110,7 +110,11 @@ namespace #else string strerror_string(int err) { - return strerror(err); // XXX Not thread-safe. + auto str = strerror(err); // XXX Not thread-safe. + if (str) [[__likely__]] + return str; + // strerror should not return NULL, but some implementations do. + return "Unknown error"; } #endif