From patchwork Sat Aug 27 13:48:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 57118 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4541E38A908A for ; Sat, 27 Aug 2022 13:49:08 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from sonata.ens-lyon.org (domu-toccata.ens-lyon.fr [140.77.166.138]) by sourceware.org (Postfix) with ESMTPS id 2BA81388DD22 for ; Sat, 27 Aug 2022 13:48:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2BA81388DD22 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bounce.ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id D225520109; Sat, 27 Aug 2022 15:48:46 +0200 (CEST) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Abf0_0lDD4iv; Sat, 27 Aug 2022 15:48:46 +0200 (CEST) Received: from begin (lfbn-bor-1-376-208.w109-215.abo.wanadoo.fr [109.215.91.208]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id A702A2011C; Sat, 27 Aug 2022 15:48:45 +0200 (CEST) Received: from samy by begin with local (Exim 4.96) (envelope-from ) id 1oRwB3-005IdB-0J; Sat, 27 Aug 2022 15:48:45 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd, commited 1/2] mach: Fix incoherency between perror and strerror Date: Sat, 27 Aug 2022 15:48:43 +0200 Message-Id: <20220827134844.1263243-2-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220827134844.1263243-1-samuel.thibault@ens-lyon.org> References: <20220827134844.1263243-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: commit-hurd@gnu.org Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 08d2024b4167 ("string: Simplify strerror_r") inadvertently made __strerror_r print unknown error system in decimal while the original code was printing it in hexadecimal. perror was kept printing in hexadecimal in 725eeb4af14c ("string: Use tls-internal on strerror_l"), let us keep both coherent. This also fixes a duplicate ':' Spotted by the libunistring testsuite test-perror2 --- sysdeps/mach/_strerror.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysdeps/mach/_strerror.c b/sysdeps/mach/_strerror.c index b179c440d3..acc00612bb 100644 --- a/sysdeps/mach/_strerror.c +++ b/sysdeps/mach/_strerror.c @@ -40,7 +40,7 @@ __strerror_r (int errnum, char *buf, size_t buflen) if (system > err_max_system || ! __mach_error_systems[system].bad_sub) { - __snprintf (buf, buflen, "%s: %d", _("Error in unknown error system: "), + __snprintf (buf, buflen, "%s%X", _("Error in unknown error system: "), errnum); return buf; } From patchwork Sat Aug 27 13:48:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 57117 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3BAF9389942D for ; Sat, 27 Aug 2022 13:49:04 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from sonata.ens-lyon.org (sonata.ens-lyon.org [140.77.166.138]) by sourceware.org (Postfix) with ESMTPS id 62EB0388DD21 for ; Sat, 27 Aug 2022 13:48:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 62EB0388DD21 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bounce.ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id A480320127; Sat, 27 Aug 2022 15:48:46 +0200 (CEST) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id y5zscaiUDwES; Sat, 27 Aug 2022 15:48:46 +0200 (CEST) Received: from begin (lfbn-bor-1-376-208.w109-215.abo.wanadoo.fr [109.215.91.208]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id 9FF0C2011A; Sat, 27 Aug 2022 15:48:45 +0200 (CEST) Received: from samy by begin with local (Exim 4.96) (envelope-from ) id 1oRwB3-005IdE-0S; Sat, 27 Aug 2022 15:48:45 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd,commited 2/2] mach: Make xpg_strerror_r set a message on error Date: Sat, 27 Aug 2022 15:48:44 +0200 Message-Id: <20220827134844.1263243-3-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220827134844.1263243-1-samuel.thibault@ens-lyon.org> References: <20220827134844.1263243-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: commit-hurd@gnu.org Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" posix advises to have strerror_r fill a message even when we are returning an error. This makes mach's xpg_strerror_r do this, like the generic version does. Spotted by the libunistring testsuite test-strerror_r --- sysdeps/mach/xpg-strerror.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sysdeps/mach/xpg-strerror.c b/sysdeps/mach/xpg-strerror.c index 92bb67e2bc..de75cc84ae 100644 --- a/sysdeps/mach/xpg-strerror.c +++ b/sysdeps/mach/xpg-strerror.c @@ -51,7 +51,11 @@ __xpg_strerror_r (int errnum, char *buf, size_t buflen) code = err_get_code (errnum); if (system > err_max_system || ! __mach_error_systems[system].bad_sub) - return EINVAL; + { + __snprintf (buf, buflen, "%s%X", _("Error in unknown error system: "), + errnum); + return EINVAL; + } es = &__mach_error_systems[system]; @@ -62,11 +66,11 @@ __xpg_strerror_r (int errnum, char *buf, size_t buflen) else estr = (const char *) _(es->subsystem[sub].codes[code]); - size_t estrlen = strlen (estr) + 1; + size_t estrlen = strlen (estr); - if (buflen < estrlen) - return ERANGE; + /* Terminate the string in any case. */ + if (buflen > 0) + *((char *) __mempcpy (buf, estr, MIN (buflen - 1, estrlen))) = '\0'; - memcpy (buf, estr, estrlen); - return 0; + return buflen <= estrlen ? ERANGE : 0; }