Bug 41659 - apr_os_locale_encoding(): retval of nl_langinfo() should be strdup'ed somehow
Summary: apr_os_locale_encoding(): retval of nl_langinfo() should be strdup'ed somehow
Status: RESOLVED FIXED
Alias: None
Product: APR
Classification: Unclassified
Component: APR (show other bugs)
Version: HEAD
Hardware: All All
: P2 minor (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-20 00:08 UTC by Moriyoshi Koizumi
Modified: 2007-04-17 14:36 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Moriyoshi Koizumi 2007-02-20 00:08:27 UTC
Whilst I didn't ever meet a problem caused by this, I spotted a possible flaw in
apr_os_locale_encoding() as shown in the following part:

--- 
APR_DECLARE(const char*) apr_os_locale_encoding (apr_pool_t *pool)
{
#if defined(HAVE_NL_LANGINFO) && defined(CODESET)
    const char *charset;

    charset = nl_langinfo(CODESET);
    if (charset && *charset) {
#ifdef _OSD_POSIX /* Bug workaround - delete as soon as fixed in OSD_POSIX */
        /* Some versions of OSD_POSIX return nl_langinfo(CODESET)="^[nN]" */
        /* Ignore the bogus information and use apr_os_default_encoding() */
        if (charset[0] != '^')
#endif
        return charset;
    }
#endif

    return apr_os_default_encoding(pool);
}
--- 

As stated in the nl_langinfo() spec
(http://www.opengroup.org/onlinepubs/009695399/functions/nl_langinfo.html ), the
pointer returned by nl_langinfo() may be transient and subject to race
conditions as well, so it's better off duplicating it instead of returning the
original one.

HTH,
Moriyoshi
Comment 1 William A. Rowe Jr. 2007-04-17 14:36:51 UTC
fixed in r529774 and it's backports to the next 0.9 and 1.2

thanks for the report!