Bug 267410 - [PATCH] strfmon_l: Fix strfmon_l(3)
Summary: [PATCH] strfmon_l: Fix strfmon_l(3)
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: standards (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-standards (Nobody)
URL: https://github.com/freebsd/freebsd-sr...
Keywords: patch
Depends on:
Blocks:
 
Reported: 2022-10-29 02:24 UTC by Jose Luis Duran
Modified: 2023-01-26 18:51 UTC (History)
1 user (show)

See Also:


Attachments
MWE (888 bytes, text/plain)
2022-10-29 02:24 UTC, Jose Luis Duran
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jose Luis Duran freebsd_committer freebsd_triage 2022-10-29 02:24:30 UTC
Created attachment 237701 [details]
MWE

Attached is a simple MWE that reproduces a few bugs in the current strfmon_l(3) code.

I have created a GitHub pull request (#620), which attempts to fix them:
https://github.com/freebsd/freebsd-src/pull/620

% ./strfmon_l_mwe 
Expected: [ **1234,57 €] [ **1.234,57 EUR]
  Actual: [ €**1234.57 ] [ EUR**1234.57 ]

Expected: [ £**1234.57] [ GBP**1,234.57]
  Actual: [ £**1234.57 ] [ GBP**1234.57 ]

Posting it here fore visibility and tracking.
Comment 1 commit-hook freebsd_committer freebsd_triage 2022-10-29 21:11:53 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=621bf91893ad96c2ec46e603bf4c5b8762e3f730

commit 621bf91893ad96c2ec46e603bf4c5b8762e3f730
Author:     Jose Luis Duran <jlduran@gmail.com>
AuthorDate: 2022-10-28 01:24:48 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-10-29 21:09:11 +0000

    strfmon_l: Use specified locale for number formatting

    strfmon_l does not take fully into consideration the explicitly passed
    locale to perform the formatting.

    Parallel universe bug report:   https://sourceware.org/bugzilla/show_bug.cgi?id=19633

    Obtained from:  Darwin
    Reviewed by:    kib
    PR:     267410
    Github PR:      #620
    MFC after:      1 week

 lib/libc/stdlib/strfmon.c            | 47 ++++++++++++++++++------------------
 lib/libc/tests/stdlib/strfmon_test.c |  4 +--
 2 files changed, 25 insertions(+), 26 deletions(-)
Comment 2 commit-hook freebsd_committer freebsd_triage 2022-10-29 21:11:53 UTC
A commit in branch main references this bug:

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

commit edcee003e5a79386653c8092af3577a112e95451
Author:     Jose Luis Duran <jlduran@gmail.com>
AuthorDate: 2022-10-27 10:01:24 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-10-29 21:08:33 +0000

    strfmon_test: Reserve space for the null terminator

    Otherwise strfmon(3) could overflow the buffer.

    Here is mostly done for correctness and illustrative purposes, as there
    is no chance it could actually happen.

    Reviewed by:    kib
    PR:     267410
    Github PR:      #620
    MFC after:      1 week

 lib/libc/tests/stdlib/strfmon_test.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Comment 3 commit-hook freebsd_committer freebsd_triage 2022-10-29 21:11:54 UTC
A commit in branch main references this bug:

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

commit d96088b3ab5f5b833a78ff363f540cc5fa2c1e78
Author:     Jose Luis Duran <jlduran@gmail.com>
AuthorDate: 2022-10-28 08:29:16 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-10-29 21:08:19 +0000

    strfmon_l(3): Add name to the man page

    Reviewed by:    kib
    PR:     267410
    Github PR:      #620
    MFC after:      1 week

 lib/libc/stdlib/strfmon.3 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2022-10-29 21:11:55 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=29972f06f95d6f5f550ac81367d5ebda8d6860a8

commit 29972f06f95d6f5f550ac81367d5ebda8d6860a8
Author:     Jose Luis Duran <jlduran@gmail.com>
AuthorDate: 2022-10-28 02:53:43 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-10-29 21:08:54 +0000

    strfmon_test: Add a test for strfmon_l

    Attempt to test the correctness of strfmon_l(3).

    Items marked with XXX represent an invalid output.

    Obtained from:  https://github.com/NetBSD/src/commit/e7eba0044fe6128291cbb7e5923c7cf7d87318cc

    Reviewed by:    kib
    PR:     267410
    Github PR:      #620
    MFC after:      1 week

 lib/libc/tests/stdlib/strfmon_test.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
Comment 5 commit-hook freebsd_committer freebsd_triage 2022-10-29 21:11:56 UTC
A commit in branch main references this bug:

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

commit f0a15aafcb863f796e2a7f94d0fd8a857fb56103
Author:     Jose Luis Duran <jlduran@gmail.com>
AuthorDate: 2022-10-28 09:20:33 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-10-29 21:09:32 +0000

    strfmon: Remove XXX marks

    phantom@'s HDD crashed with the final version of strfmon.c, as explained
    in 9d430a5991d3f64a75fee951a1efab3593207832.

    Now there are tests in place that cover these code paths.

    Reviewed by:    kib
    PR:     267410
    Github PR:      #620
    MFC after:      1 week

 lib/libc/stdlib/strfmon.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)