Return-Path: X-Original-To: apmail-subversion-commits-archive@minotaur.apache.org Delivered-To: apmail-subversion-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E17CF10AA4 for ; Mon, 21 Oct 2013 10:32:11 +0000 (UTC) Received: (qmail 99079 invoked by uid 500); 21 Oct 2013 10:32:10 -0000 Delivered-To: apmail-subversion-commits-archive@subversion.apache.org Received: (qmail 99066 invoked by uid 500); 21 Oct 2013 10:32:09 -0000 Mailing-List: contact commits-help@subversion.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@subversion.apache.org Delivered-To: mailing list commits@subversion.apache.org Received: (qmail 99059 invoked by uid 99); 21 Oct 2013 10:32:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Oct 2013 10:32:07 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Oct 2013 10:32:06 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 155982388868; Mon, 21 Oct 2013 10:31:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1534083 - in /subversion/trunk/subversion/libsvn_subr: config_win.c nls.c Date: Mon, 21 Oct 2013 10:31:45 -0000 To: commits@subversion.apache.org From: rhuijben@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131021103146.155982388868@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rhuijben Date: Mon Oct 21 10:31:45 2013 New Revision: 1534083 URL: http://svn.apache.org/r1534083 Log: Simplify some Win32 specific code by using svn_subr__win32_utf16_to_utf8. * subversion/libsvn_subr/config_win.c (includes): Add private/svn_subr_private.h. (svn_config__win_config_path): Use svn_subr__win32_utf16_to_utf8. (parse_section): Add comment. * subversion/libsvn_subr/nls.c (includes): Add svn_subr_private.h. (svn_nls_init): Simplify win32 specific code. Assume Windows 2000 or later. Report buffer overflows instead of using a truncated path. Modified: subversion/trunk/subversion/libsvn_subr/config_win.c subversion/trunk/subversion/libsvn_subr/nls.c Modified: subversion/trunk/subversion/libsvn_subr/config_win.c URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/config_win.c?rev=1534083&r1=1534082&r2=1534083&view=diff ============================================================================== --- subversion/trunk/subversion/libsvn_subr/config_win.c (original) +++ subversion/trunk/subversion/libsvn_subr/config_win.c Mon Oct 21 10:31:45 2013 @@ -44,10 +44,11 @@ #include "svn_path.h" #include "svn_pools.h" #include "svn_utf.h" +#include "private/svn_subr_private.h" svn_error_t * svn_config__win_config_path(const char **folder, int system_path, - apr_pool_t *pool) + apr_pool_t *result_pool) { /* ### Adding CSIDL_FLAG_CREATE here, because those folders really must exist. I'm not too sure about the SHGFP_TYPE_CURRENT @@ -56,8 +57,6 @@ svn_config__win_config_path(const char * | CSIDL_FLAG_CREATE); WCHAR folder_ucs2[MAX_PATH]; - int inwords, outbytes, outlength; - char *folder_utf8; if (S_OK != SHGetFolderPathW(NULL, csidl, NULL, SHGFP_TYPE_CURRENT, folder_ucs2)) @@ -66,26 +65,8 @@ svn_config__win_config_path(const char * ? "Can't determine the system config path" : "Can't determine the user's config path")); - /* ### When mapping from UCS-2 to UTF-8, we need at most 3 bytes - per wide char, plus extra space for the nul terminator. */ - inwords = lstrlenW(folder_ucs2); - outbytes = outlength = 3 * (inwords + 1); - - folder_utf8 = apr_palloc(pool, outlength); - - outbytes = WideCharToMultiByte(CP_UTF8, 0, folder_ucs2, inwords, - folder_utf8, outbytes, NULL, NULL); - - if (outbytes == 0) - return svn_error_wrap_apr(apr_get_os_error(), - "Can't convert config path to UTF-8"); - - /* Note that WideCharToMultiByte does _not_ terminate the - outgoing buffer. */ - folder_utf8[outbytes] = '\0'; - *folder = folder_utf8; - - return SVN_NO_ERROR; + return svn_error_trace(svn_subr__win32_utf16_to_utf8(folder, folder_ucs2, + result_pool)); } @@ -97,6 +78,8 @@ svn_config__win_config_path(const char * #define SVN_REG_DEFAULT_NAME_SIZE 2048 #define SVN_REG_DEFAULT_VALUE_SIZE 8192 +/* ### This function should be converted to use the unicode functions + ### instead of the ansi functions */ static svn_error_t * parse_section(svn_config_t *cfg, HKEY hkey, const char *section, svn_stringbuf_t *option, svn_stringbuf_t *value) Modified: subversion/trunk/subversion/libsvn_subr/nls.c URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/nls.c?rev=1534083&r1=1534082&r2=1534083&view=diff ============================================================================== --- subversion/trunk/subversion/libsvn_subr/nls.c (original) +++ subversion/trunk/subversion/libsvn_subr/nls.c Mon Oct 21 10:31:45 2013 @@ -37,6 +37,8 @@ #include "svn_pools.h" #include "svn_path.h" +#include "private/svn_subr_private.h" + #include "svn_private_config.h" svn_error_t * @@ -53,69 +55,38 @@ svn_nls_init(void) { #ifdef WIN32 WCHAR ucs2_path[MAX_PATH]; - char* utf8_path; + const char* utf8_path; const char* internal_path; - apr_pool_t* pool; - apr_size_t inwords, outbytes, outlength; + apr_pool_t* scratch_pool; - pool = svn_pool_create(0); + scratch_pool = svn_pool_create(NULL); /* get exe name - our locale info will be in '../share/locale' */ - inwords = GetModuleFileNameW(0, ucs2_path, - sizeof(ucs2_path) / sizeof(ucs2_path[0])); - if (! inwords) + GetModuleFileNameW(NULL, ucs2_path, + sizeof(ucs2_path) / sizeof(ucs2_path[0])) + if (apr_get_os_error()) { - /* We must be on a Win9x machine, so attempt to get an ANSI path, - and convert it to Unicode. */ - CHAR ansi_path[MAX_PATH]; - - if (GetModuleFileNameA(0, ansi_path, sizeof(ansi_path))) - { - inwords = - MultiByteToWideChar(CP_ACP, 0, ansi_path, -1, ucs2_path, - sizeof(ucs2_path) / sizeof(ucs2_path[0])); - if (! inwords) - { - err = - svn_error_createf(APR_EINVAL, NULL, - _("Can't convert string to UCS-2: '%s'"), - ansi_path); - } - } - else - { - err = svn_error_create(APR_EINVAL, NULL, - _("Can't get module file name")); - } + err = svn_error_wrap_apr(apr_get_os_error() + _("Can't get module file name")); } if (! err) - { - outbytes = outlength = 3 * (inwords + 1); - utf8_path = apr_palloc(pool, outlength); - - outbytes = WideCharToMultiByte(CP_UTF8, 0, ucs2_path, inwords, - utf8_path, outbytes, NULL, NULL); + err = svn_subr__win32_utf16_to_utf8(&utf8_path, ucs2_path, + scratch_pool); - if (outbytes == 0) - { - err = svn_error_wrap_apr(apr_get_os_error(), - _("Can't convert module path " - "to UTF-8 from UCS-2: '%s'"), - ucs2_path); - } - else - { - utf8_path[outlength - outbytes] = '\0'; - internal_path = svn_dirent_internal_style(utf8_path, pool); - /* get base path name */ - internal_path = svn_dirent_dirname(internal_path, pool); - internal_path = svn_dirent_join(internal_path, - SVN_LOCALE_RELATIVE_PATH, - pool); - bindtextdomain(PACKAGE_NAME, internal_path); - } + if (! err) + { + internal_path = svn_dirent_internal_style(utf8_path, scratch_pool); + /* get base path name */ + internal_path = svn_dirent_dirname(internal_path, scratch_pool); + internal_path = svn_dirent_join(internal_path, + SVN_LOCALE_RELATIVE_PATH, + scratch_pool); + SVN_ERR(svn_dirent_get_absolute(&internal_path, internal_path, + scratch_pool)); + bindtextdomain(PACKAGE_NAME, internal_path); } - svn_pool_destroy(pool); + + svn_pool_destroy(scratch_pool); } #else /* ! WIN32 */ bindtextdomain(PACKAGE_NAME, SVN_LOCALE_DIR);