php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #70542
Patch bug70542 revision 2015-10-24 05:26 UTC by kalle@php.net
Patch gettext-tests-valid-categories revision 2015-09-24 13:52 UTC by rainer dot jung at kippdata dot de

Patch bug70542 for Gettext related Bug #70542

Patch version 2015-10-24 05:26 UTC

Return to Bug #70542 | Download this patch
Patch Revisions:

Developer: kalle@php.net

diff --git a/ext/gettext/gettext.c b/ext/gettext/gettext.c
index dfe94c7..e3127c3 100644
--- a/ext/gettext/gettext.c
+++ b/ext/gettext/gettext.c
@@ -150,6 +150,40 @@ ZEND_GET_MODULE(php_gettext)
 		RETURN_FALSE; \
 	}
 
+/* This piece of code is to dodge a crash in Solaris
+ * which happens when $category is -1. Note that if -1 
+ * is supplied, we simply change it into being LC_ALL 
+ * but only for Solaris. Hence why the `case -1:' switch 
+ * below remains for other systems where this is not a 
+ * problem, like Windows.
+ */
+#if defined(__sun) && defined(__SVR4)
+# define PHP_GETTEXT_CATEGORY_NORMALIZE \
+	if (category == -1) { \
+		category = LC_ALL; \
+	}
+#else
+# define PHP_GETTEXT_CATEGORY_NORMALIZE
+#endif
+
+#define PHP_GETTEXT_CATEGORY_CHECK(category) \
+	PHP_GETTEXT_CATEGORY_NORMALIZE \
+	switch (category) { \
+		case LC_ALL: \
+		case LC_COLLATE: \
+		case LC_CTYPE: \
+		case LC_MESSAGES: \
+		case LC_MONETARY: \
+		case LC_NUMERIC: \
+		case LC_TIME: \
+		case -1: \
+		break; \
+		default: \
+			php_error_docref(NULL, E_WARNING, "invalid category supplied"); \
+		break; \
+	}
+
+
 PHP_MINFO_FUNCTION(php_gettext)
 {
 	php_info_print_table_start();
@@ -240,6 +274,7 @@ PHP_NAMED_FUNCTION(zif_dcgettext)
 
 	PHP_GETTEXT_DOMAIN_LENGTH_CHECK
 	PHP_GETTEXT_LENGTH_CHECK("msgid", msgid_len)
+	PHP_GETTEXT_CATEGORY_CHECK(category)
 
 	msgstr = dcgettext(domain, msgid, category);
 
@@ -349,6 +384,7 @@ PHP_NAMED_FUNCTION(zif_dcngettext)
 	PHP_GETTEXT_DOMAIN_LENGTH_CHECK
 	PHP_GETTEXT_LENGTH_CHECK("msgid1", msgid1_len)
 	PHP_GETTEXT_LENGTH_CHECK("msgid2", msgid2_len)
+	PHP_GETTEXT_CATEGORY_CHECK(category)
 
 	msgstr = dcngettext(domain, msgid1, msgid2, count, category);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC