#23225 [NEW]: money_format hangs on incorrect format

From: Date: Tue, 15 Apr 2003 12:32:20 +0000
Subject: #23225 [NEW]: money_format hangs on incorrect format
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-37704@lists.php.net to get a copy of this message
From:             marcot at tabini dot ca
Operating system: Linux RH 9
PHP version:      5CVS-2003-04-15 (dev)
PHP Bug Type:     Strings related
Bug description:  money_format hangs on incorrect format

Calling money_format with an apparently correct format

<?php

  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"
 #endif
@@ -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);






-- 
Edit bug report at http://bugs.php.net/?id=23225&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=23225&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=23225&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=23225&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=23225&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=23225&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=23225&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=23225&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=23225&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=23225&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=23225&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=23225&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=23225&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=23225&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=23225&r=gnused



Thread (2 messages)

« previous php.bugs (#37704) next »