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:

Gettext is not thread-safe.  You shouldn't need to worry about trying to
get gettext working in threads.  The underlying gettext library would
first have to be made thread-safe and no longer able to be driven by
environment variables.



Gettext can be driven by environment variables and unless you have a way
to set up completely different environments for each thread, then there
is never going to be a way to reliably use gettext in threads.  One
thread could set an env var to one value and another thread in the same
process set the env var to a different value and both of these threads
would see the value set by the latest thread.  And gettext would behave
according to the latest setting which would totally screw up the earlier
thread.





.


Previous Comments:
------------------------------------------------------------------------
[2010-11-26 20:43:18] paj...@php.net

Thanks for the patch. But it is sadly not correct. We have to get the
realpath of the directory argument in TS mode.

------------------------------------------------------------------------
[2010-11-26 20:37:50] greno at verizon dot net

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.





.

------------------------------------------------------------------------
[2010-11-26 18:17:03] paj...@php.net

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.





.

------------------------------------------------------------------------


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

Reply via email to