From nobody Tue Apr 23 17:00:06 2024 X-Original-To: standards@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 4VP7dy1zPKz5Hd64 for ; Tue, 23 Apr 2024 17:00:06 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VP7dx6nvSz4FNy for ; Tue, 23 Apr 2024 17:00:05 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713891606; a=rsa-sha256; cv=none; b=ovg0HWNfleu9C4yIf+dGLfmhbVrMoF65ir+af3bxkdg3pe3EppTpsJ8Tf/0BgYwetFYwvw eRM+yhxAy2CVKaqnn7F4oAE7kKtqjKbO8Be4OHzPaNJCz3EXgfrs3cNF8jw17w0eXYE0cR J1CNGlqE3DhqNAL0911IcqJcJ+YH7kHKz+RILqoZ+4FaYD3F/K1+4zmMpdMHrq4LgYYSjt dxoPtG1Rxl1a9n8b+TFNkPPt4v6vJCZxCdM2DBP1abxXZtC8gWTG2A/ka+bEPGwLUXTbex CkaQOf7D0u+5OucP6TLczrY5MIQS2PfyBC+HLRvuOGoUzekhlRine6t+sHLOLA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713891606; 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: in-reply-to:in-reply-to:references:references; bh=g2GezY5X8LuNKvWkA+kgB8udCAYNgXE1IMpk9Hew3lo=; b=MXy8APfrWzxzpFxz4fUgu7zcZAP79eJiHNYqSHTKdDwQ7i8SDF2qSYP4ZJplg1uLjSYrlG mmBPTVsYWHJSCWsR6Jc0oS8iPZZ8QoAeUABtBGtzPIv0eBiHH7vkFtUcVWcgdrUlAu0MIf KnY/t9pObq4m6e6waCfP8NQ4SrtvlVPICXr7tWeDmQgHo0ikBh6xk0DViS/vBHz3hAmj83 f44TMUUCawYqzZmd2CWsnZnB3eK6gJ4ekwi4Vchax880yU0xc5Jh/ep6lxtsM6+UUo9Zi2 pPN065ANJsYMYYuG5tCkQYatn74kJiyPsZZW/Ih/DtgrCfidSobLm+DlW0BlXQ== 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 4VP7dx6QNczfxw for ; Tue, 23 Apr 2024 17:00:05 +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 43NH05ou025393 for ; Tue, 23 Apr 2024 17:00:05 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 43NH05As025381 for standards@FreeBSD.org; Tue, 23 Apr 2024 17:00:05 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: standards@FreeBSD.org Subject: [Bug 278556] strerror-related race condition and standards violation in printf and friends Date: Tue, 23 Apr 2024 17:00:06 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: standards X-Bugzilla-Version: Unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Many People X-Bugzilla-Who: imp@FreeBSD.org X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: standards@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Standards compliance List-Archive: https://lists.freebsd.org/archives/freebsd-standards List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: freebsd-standards@freebsd.org Sender: owner-freebsd-standards@FreeBSD.org MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D278556 Warner Losh changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |imp@FreeBSD.org --- Comment #1 from Warner Losh --- I came to the same suggested solution after only reading the first half of = your excellent bug report, so I agree with the suggested solution. ML_TEXTMAX is huge, but not really anymore (2k). The following leverages off of the buffe= r we already need to allocate for digit accumulation: diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index 6c7c6982c8dc..622cb57f5e7d 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -44,7 +44,7 @@ */ #include "namespace.h" -#include +#include #include #include @@ -354,7 +354,7 @@ __vfprintf(FILE *fp, locale_t locale, const char *fmt0, va_list ap) int prsize; /* max size of printed field */ const char *xdigs; /* digits for %[xX] conversion */ struct io_state io; /* I/O buffering state */ - char buf[BUF]; /* buffer with space for digits of uintmax_t */ + char buf[MAX(BUF, NL_TEXTMAX)]; /* buffer with space for digits of uintma= x_t or errno string */ char ox[2]; /* space for 0x; ox[1] is either x, X, or \= 0 */ union arg *argtable; /* args, built due to positional arg */ union arg statargtable [STATIC_ARG_TBL_SIZE]; @@ -829,7 +829,9 @@ reswitch: switch (ch) { break; #endif /* !NO_FLOATING_POINT */ case 'm': - cp =3D strerror(saved_errno); + if (strerror_r(saved_errno, buf, sizeof(buf)) !=3D 0) + strlcpy(buf, "error not available", sizeof(buf)); + cp =3D buf; size =3D (prec >=3D 0) ? strnlen(cp, prec) : strlen= (cp); sign =3D '\0'; break; --=20 You are receiving this mail because: You are the assignee for the bug.=