|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23225 money_format hangs on incorrect format
Submitted: 2003-04-15 07:32 UTC Modified: 2003-04-15 20:08 UTC
From: marcot at tabini dot ca Assigned:
Status: Closed Package: Strings related
PHP Version: 5CVS-2003-04-15 (dev) OS: Linux RH 9
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: marcot at tabini dot ca
New email:
PHP Version: OS:


 [2003-04-15 07:32 UTC] marcot at tabini dot ca
Calling money_format with an apparently correct format


  setlocale (LC_MONETARY, 'en_US');
  echo money_format ('%#.2n', 1000);


causes PHP to hang (tested with 4.3.1 and 5-dev).

Apparently, strfmon() returns -1 (errno is 22, indicating an invalid parameter) even though the format should theoretically be correct. The -1 is not trapped in strings.c, resulting in a huge string full of binary data being returned.

Here's my suggested patch, returning false on an error from strfmon().

Index: string.c
RCS file: /repository/php4/ext/standard/string.c,v
retrieving revision 1.374
diff -u -r1.374 string.c
--- string.c    13 Apr 2003 22:59:19 -0000      1.374
+++ string.c    15 Apr 2003 12:30:14 -0000
@@ -46,6 +46,7 @@
 #include "php_globals.h"
 #include "basic_functions.h"
 #include "php_smart_str.h"
+#include "zend_operators.h"
 #ifdef ZTS
 #include "TSRM.h"
@@ -4372,7 +4373,11 @@
        str_len = format_len + 1024;
        str = emalloc(str_len);
-       str_len = strfmon(str, str_len, format, value);
+       str_len = strfmon(str, str_len, format, value);
+       if (str_len == -1)
+               RETURN_FALSE;
        str[str_len] = 0;
        RETURN_STRINGL(erealloc(str, str_len + 1), str_len, 0);


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-15 20:08 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Dec 01 04:01:29 2023 UTC