Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 03 Dec 2025 02:38:28 +0000
From:      Jose Luis Duran <jlduran@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 8dc8e3011d05 - stable/14 - strfmon: EINVAL if the '+' flag and both signs are empty
Message-ID:  <692fa2a4.30fac.47c41e8d@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/14 has been updated by jlduran:

URL: https://cgit.FreeBSD.org/src/commit/?id=8dc8e3011d05bdadb3e62fe99fbb054e33bfd8f2

commit 8dc8e3011d05bdadb3e62fe99fbb054e33bfd8f2
Author:     Jose Luis Duran <jlduran@FreeBSD.org>
AuthorDate: 2025-11-26 20:34:55 +0000
Commit:     Jose Luis Duran <jlduran@FreeBSD.org>
CommitDate: 2025-12-03 02:34:21 +0000

    strfmon: EINVAL if the '+' flag and both signs are empty
    
    According to the Open Group Base Specifications Issue 8[1], strfmon(3)
    should return EINVAL when the '+' flag was included in a conversion
    specification and the locale's positive_sign and negative_sign values
    would both be returned by localeconv(3) as empty strings.
    
    Austin Group Defect 1199[2] is applied, adding the [EINVAL] error.
    
    [1]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/strfmon.html
    [2]: https://www.austingroupbugs.net/view.php?id=1199
    
    Reviewed by:    kib
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D53912
    
    (cherry picked from commit 1fd018972a18b682521bb8f004dfd162327e5db2)
---
 lib/libc/stdlib/strfmon.3            | 12 +++++++++++-
 lib/libc/stdlib/strfmon.c            |  4 +++-
 lib/libc/tests/stdlib/strfmon_test.c |  8 ++++----
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/lib/libc/stdlib/strfmon.3 b/lib/libc/stdlib/strfmon.3
index 20cc560d401d..d537d9d05fa7 100644
--- a/lib/libc/stdlib/strfmon.3
+++ b/lib/libc/stdlib/strfmon.3
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd December 6, 2023
+.Dd November 24, 2025
 .Dt STRFMON 3
 .Os
 .Sh NAME
@@ -182,6 +182,16 @@ function will fail if:
 Conversion stopped due to lack of space in the buffer.
 .It Bq Er EINVAL
 The format string is invalid.
+.It Bq Er EINVAL
+The
+.Cm +
+flag was included in a conversion specification and the locale's
+.Va positive_sign
+and
+.Va negative_sign
+values would both be returned by
+.Xr localeconv 3
+as empty strings.
 .It Bq Er ENOMEM
 Not enough memory for temporary buffers.
 .El
diff --git a/lib/libc/stdlib/strfmon.c b/lib/libc/stdlib/strfmon.c
index 230d194233f5..b19d9fc43369 100644
--- a/lib/libc/stdlib/strfmon.c
+++ b/lib/libc/stdlib/strfmon.c
@@ -171,7 +171,9 @@ literal:
 				flags &= ~(NEED_GROUPING);
 				continue;
 			case '+':	/* use locale defined signs */
-				if (flags & SIGN_POSN_USED)
+				if ((flags & SIGN_POSN_USED) ||
+				    ((lc->positive_sign[0] == '\0') &&
+				    (lc->negative_sign[0] == '\0')))
 					goto format_error;
 				flags |= (SIGN_POSN_USED | LOCALE_POSN);
 				continue;
diff --git a/lib/libc/tests/stdlib/strfmon_test.c b/lib/libc/tests/stdlib/strfmon_test.c
index 3c97d61ba82c..165ddcc2ab56 100644
--- a/lib/libc/tests/stdlib/strfmon_test.c
+++ b/lib/libc/tests/stdlib/strfmon_test.c
@@ -234,11 +234,11 @@ ATF_TC_BODY(strfmon_plus_or_parenthesis, tc)
 	if (setlocale(LC_MONETARY, "C") == NULL)
 		atf_tc_skip("unable to setlocale(): %s", tests[i].locale);
 
-	/* ATF_CHECK_ERRNO(EINVAL, strfmon(actual, sizeof(actual) - 1,
-	    "[%+n] [%+n]", 123.45, -123.45)); XXX */
+	ATF_CHECK_ERRNO(EINVAL, strfmon(actual, sizeof(actual) - 1,
+	    "[%+n] [%+n]", 123.45, -123.45));
 
-	/* ATF_CHECK_ERRNO(EINVAL, strfmon(actual, sizeof(actual) - 1,
-	    "[%+i] [%+i]", 123.45, -123.45)); XXX */
+	ATF_CHECK_ERRNO(EINVAL, strfmon(actual, sizeof(actual) - 1,
+	    "[%+i] [%+i]", 123.45, -123.45));
 }
 
 ATF_TC(strfmon_l);


help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?692fa2a4.30fac.47c41e8d>