Edit report at http://bugs.php.net/bug.php?id=53251&edit=1
ID: 53251
Comment by: greno at verizon dot net
Reported by: jeanseb at au-fil-du dot net
Summary: bindtextdomain with null directory doesn't return
the previously set
Status: Assigned
Type: Bug
Package: Gettext related
Operating System: Debian 5.0.6
PHP Version: 5.3.3
Assigned To: pajoye
Block user comment: N
Private report: N
New Comment:
I've attached a patch (fix_broken_bindtextdomain) to the bug which
should correct the bindtextdomain problem.
And I prepared phpt tests (see my second set of phpt tests zip file in a
previous posting) that can test the bindtextdomain NULL arg
functionality.
So everything is here and available to fix bindtextdomain in PHP 5.2.15
and 5.3.3.
.
Previous Comments:
------------------------------------------------------------------------
[2010-11-26 18:17:03] [email protected]
That's exaclty what I said in my comment earlier this week.
------------------------------------------------------------------------
[2010-11-26 16:50:25] greno at verizon dot net
Looking at bindtextdomain gettext.c in the current 5_3 tree:
PHP_NAMED_FUNCTION(zif_bindtextdomain)
{
char *domain, *dir;
int domain_len, dir_len;
char *retval, dir_name[MAXPATHLEN];
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
&domain, &domain_len, &dir, &dir_len) == FAILURE) {
return;
}
PHP_GETTEXT_DOMAIN_LENGTH_CHECK
if (domain[0] == '\0') {
php_error(E_WARNING, "The first parameter of
bindtextdomain must not be empty");
RETURN_FALSE;
}
if (dir[0] != '\0' && strcmp(dir, "0")) {
if (!VCWD_REALPATH(dir, dir_name)) {
RETURN_FALSE;
}
} else if (!VCWD_GETCWD(dir_name, MAXPATHLEN)) {
RETURN_FALSE;
}
retval = bindtextdomain(domain, dir_name);
RETURN_STRING(retval, 1);
}
==================================================
This logic in that function makes no sense with respect to
bindtextdomain.
The function should ONLY need to do this:
PHP_NAMED_FUNCTION(zif_bindtextdomain)
{
char *domain, *dir;
int domain_len, dir_len;
char *retval, dir_name[MAXPATHLEN];
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
&domain, &domain_len, &dir, &dir_len) == FAILURE) {
return;
}
PHP_GETTEXT_DOMAIN_LENGTH_CHECK
if (domain[0] == '\0') {
php_error(E_WARNING, "The first parameter of
bindtextdomain must not be empty");
RETURN_FALSE;
}
retval = bindtextdomain(domain, dir_name);
RETURN_STRING(retval, 1);
}
==================================================
All that should be necessary is to check that the first argument
(domain) is not NULL and then just return the result of calling the
underlying bindtextdomain. Nothing else needs to be checked.
All that is happening is that a string representing a potential
directory path is being bound to a domain name OR a NULL directory arg
is passed in which case the underlying bindtextdomain will return the
previous setting.
Can this change PLEASE be made asap and put into 5.2.15 and 5.3.3?
It needs to get into 5.2.15 because that is the last rev from my
understanding for the 5.2 releases and as this is currently being used
almost everywhere right now it is important that the 5.2 release series
have a fix for the broken bindtextdomain function. The 5.3.3 is not as
important but certainly would be nice to get this fix out quickly.
.
------------------------------------------------------------------------
[2010-11-25 15:59:58] greno at verizon dot net
One important thing to note about the tests:
It is not necessary for the domain directory string set in
bindtextdomain to actually exist in the file system at the time of
binding.
A script could be dynamically creating this directory later on.
The binding is to nothing more than a string that represents a potential
directory path.
It is up to the user to make sure that the string bound by
bindtextdomain actually represents a valid path at time of execution of
gettext commands.
I've tested this behavior in other languages and that is how they work.
.
------------------------------------------------------------------------
[2010-11-25 02:41:25] greno at verizon dot net
Found that Expect does not need quotes around strings. Ignore previous
tests.
Reposted updated tests:
http://greno-misc.googlecode.com/files/bindtextdomaintests-2.zip
.
------------------------------------------------------------------------
[2010-11-25 02:27:08] greno at verizon dot net
I think these phpt tests will work. I ran them from the command line
and they ran fine. Had no idea what to name them so you may have to
adjust.
http://greno-misc.googlecode.com/files/bindtextdomaintests.zip
.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/bug.php?id=53251
--
Edit this bug report at http://bugs.php.net/bug.php?id=53251&edit=1