[ros-diffs] [gschneider] 44650: [kernel32] Viliam Lejcik (lejcik AT gmail DOT com>: Various locale fixes (missing checks, wrong or no errors set etc.) See issue #4898 for more details.

gschneider at svn.reactos.org gschneider at svn.reactos.org
Fri Dec 18 20:54:43 CET 2009


Author: gschneider
Date: Fri Dec 18 20:54:43 2009
New Revision: 44650

URL: http://svn.reactos.org/svn/reactos?rev=44650&view=rev
Log:
[kernel32]
Viliam Lejcik (lejcik AT gmail DOT com>: Various locale fixes (missing checks, wrong or no errors set etc.)
See issue #4898 for more details.

Modified:
    trunk/reactos/dll/win32/kernel32/misc/lang.c
    trunk/reactos/dll/win32/kernel32/misc/lcformat.c

Modified: trunk/reactos/dll/win32/kernel32/misc/lang.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/lang.c?rev=44650&r1=44649&r2=44650&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/lang.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/misc/lang.c [iso-8859-1] Fri Dec 18 20:54:43 2009
@@ -219,8 +219,7 @@
             break;
 
         default:
-            // FIXME: Unknown date format
-            SetLastError(ERROR_INVALID_PARAMETER);
+            SetLastError(ERROR_INVALID_FLAGS);
             return FALSE;
     }
     return TRUE;
@@ -288,8 +287,7 @@
             break;
 
         default:
-            // FIXME: Unknown date format
-            SetLastError(ERROR_INVALID_PARAMETER);
+            SetLastError(ERROR_INVALID_FLAGS);
             return FALSE;
     }
     return TRUE;
@@ -334,7 +332,10 @@
     InitializeObjectAttributes(&attr, &keyName, OBJ_CASE_INSENSITIVE, hRootKey, NULL);
 
     if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ) != STATUS_SUCCESS)
+    {
+        SetLastError( ERROR_BADDB );
         hkey = 0;
+    }
 
     return hkey;
 }
@@ -2397,6 +2398,8 @@
     case LGRPID_SUPPORTED:
 
         hKey = NLS_RegOpenKey( 0, szLangGroupsKeyName );
+        if (!hKey)
+            break;
 
         swprintf( szValueName, szFormat, LanguageGroup );
 
@@ -2408,10 +2411,13 @@
                 bInstalled = TRUE;
         }
 
-        if (hKey)
-            NtClose( hKey );
+        NtClose( hKey );
 
         break;
+
+    default:
+        DPRINT("Invalid flags: %lx\n", dwFlags);
+        return FALSE;
     }
 
     if ((dwFlags == LGRPID_SUPPORTED && bSupported) ||
@@ -2440,7 +2446,7 @@
  */
 BOOL WINAPI
 IsValidLocale(LCID Locale,
-	      DWORD dwFlags)
+              DWORD dwFlags)
 {
     OBJECT_ATTRIBUTES ObjectAttributes;
     PKEY_VALUE_PARTIAL_INFORMATION KeyInfo;
@@ -2452,6 +2458,7 @@
     HANDLE KeyHandle;
     PWSTR ValueData;
     NTSTATUS Status;
+    BOOL Installed = FALSE;
 
     DPRINT("IsValidLocale() called\n");
 
@@ -2485,6 +2492,7 @@
     if (!NT_SUCCESS(Status))
     {
         DPRINT("NtOpenKey() failed (Status %lx)\n", Status);
+        SetLastError(ERROR_BADDB);
         return FALSE;
     }
 
@@ -2526,19 +2534,30 @@
 
     ValueData = (PWSTR)&KeyInfo->Data[0];
     if ((KeyInfo->Type == REG_SZ) &&
-        (KeyInfo->DataLength == 2 * sizeof(WCHAR)) &&
-        (ValueData[0] == L'1'))
-    {
-        DPRINT("Locale is supported and installed\n");
-        RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
-        return TRUE;
+        (KeyInfo->DataLength == 2 * sizeof(WCHAR)))
+    {
+        /* Find out if there is support for the language group
+         * installed, to which this language belongs */
+        KeyHandle = NLS_RegOpenKey(0, szLangGroupsKeyName);
+        if (KeyHandle)
+        {
+            WCHAR Value[2];
+            if (NLS_RegGetDword(KeyHandle, ValueData, (LPDWORD) Value) &&
+                Value[0] == L'1')
+            {
+                Installed = TRUE;
+                DPRINT("Locale is supported and installed\n");
+            }
+
+            NtClose(KeyHandle);
+        }
     }
 
     RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
 
     DPRINT("IsValidLocale() called\n");
 
-    return FALSE;
+    return Installed;
 }
 
 /*

Modified: trunk/reactos/dll/win32/kernel32/misc/lcformat.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/lcformat.c?rev=44650&r1=44649&r2=44650&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/lcformat.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/misc/lcformat.c [iso-8859-1] Fri Dec 18 20:54:43 2009
@@ -109,7 +109,7 @@
 }
 
 /**************************************************************************
- * NLS_isSystemLocale <internal>
+ * NLS_getDefaultLocale <internal>
  *
  * Return default system or user locale
  */
@@ -1023,7 +1023,7 @@
   {
       lcid = NLS_getDefaultLocale(lcid);
   }
-  else if(!IsValidLocale(lcid, 0))
+  else if(!IsValidLocale(lcid, LCID_INSTALLED))
   {
       SetLastError(ERROR_INVALID_PARAMETER);
       return 0;
@@ -1403,8 +1403,17 @@
           lpCurrencyStr,
           cchOut);
 
+  if(NLS_isSystemLocale(lcid))
+  {
+    lcid = NLS_getDefaultLocale(lcid);
+  }
+  else if(!IsValidLocale(lcid, LCID_INSTALLED))
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return 0;
+  }
+
   if (!lpszValue || cchOut < 0 || (cchOut > 0 && !lpCurrencyStr) ||
-      !IsValidLocale(lcid, 0) ||
       (lpFormat && (dwFlags || !lpFormat->lpDecimalSep || !lpFormat->lpThousandSep ||
       !lpFormat->lpCurrencySymbol || lpFormat->NegativeOrder > 15 ||
       lpFormat->PositiveOrder > 3)))




More information about the Ros-diffs mailing list