]> granicus.if.org Git - php/commitdiff
use safer functions, check error value
authorStanislav Malyshev <stas@php.net>
Sat, 17 Feb 2007 01:45:52 +0000 (01:45 +0000)
committerStanislav Malyshev <stas@php.net>
Sat, 17 Feb 2007 01:45:52 +0000 (01:45 +0000)
ext/pspell/pspell.c

index 478d6ad9e5de0ec73e8d7f8bb8e01b7a64165c4e..c9e5b806a2ae5d68124e7b5700a742e6e9e026f2 100644 (file)
@@ -186,16 +186,19 @@ static PHP_FUNCTION(pspell_new)
         * pointing to the location of the dictionaries
         */
        if(0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) {
+               LONG result;
                dwLen = sizeof(aspell_dir) - 1;
-               RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen);
+               result = RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen);
                RegCloseKey(hkey);
-               strcpy(data_dir, aspell_dir);
-               strcat(data_dir, "\\data");
-               strcpy(dict_dir, aspell_dir);
-               strcat(dict_dir, "\\dict");
-
-               pspell_config_replace(config, "data-dir", data_dir);
-               pspell_config_replace(config, "dict-dir", dict_dir);
+               if(result == ERROR_SUCCESS) {
+                       strlcpy(data_dir, aspell_dir, sizeof(data_dir));
+                       strlcat(data_dir, "\\data", sizeof(data_dir));
+                       strlcpy(dict_dir, aspell_dir, sizeof(dict_dir));
+                       strlcat(dict_dir, "\\dict", sizeof(dict_dir));
+
+                       pspell_config_replace(config, "data-dir", data_dir);
+                       pspell_config_replace(config, "dict-dir", dict_dir);
+               }
        }
 #endif
 
@@ -291,16 +294,19 @@ static PHP_FUNCTION(pspell_new_personal)
         * pointing to the location of the dictionaries
         */
        if(0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) {
+               LONG result;
                dwLen = sizeof(aspell_dir) - 1;
-               RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen);
+               result = RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen);
                RegCloseKey(hkey);
-               strcpy(data_dir, aspell_dir);
-               strcat(data_dir, "\\data");
-               strcpy(dict_dir, aspell_dir);
-               strcat(dict_dir, "\\dict");
-
-               pspell_config_replace(config, "data-dir", data_dir);
-               pspell_config_replace(config, "dict-dir", dict_dir);
+               if(result == ERROR_SUCCESS) {
+                       strlcpy(data_dir, aspell_dir, sizeof(data_dir));
+                       strlcat(data_dir, "\\data", sizeof(data_dir));
+                       strlcpy(dict_dir, aspell_dir, sizeof(dict_dir));
+                       strlcat(dict_dir, "\\dict", sizeof(dict_dir));
+
+                       pspell_config_replace(config, "data-dir", data_dir);
+                       pspell_config_replace(config, "dict-dir", dict_dir);
+               }
        }
 #endif
 
@@ -649,16 +655,19 @@ static PHP_FUNCTION(pspell_config_create)
      * pointing to the location of the dictionaries
      */
        if(0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) {
+               LONG result;
                dwLen = sizeof(aspell_dir) - 1;
-               RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen);
+               result = RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen);
                RegCloseKey(hkey);
-               strcpy(data_dir, aspell_dir);
-               strcat(data_dir, "\\data");
-               strcpy(dict_dir, aspell_dir);
-               strcat(dict_dir, "\\dict");
-
-               pspell_config_replace(config, "data-dir", data_dir);
-               pspell_config_replace(config, "dict-dir", dict_dir);
+               if(result == ERROR_SUCCESS) {
+                       strlcpy(data_dir, aspell_dir, sizeof(data_dir));
+                       strlcat(data_dir, "\\data", sizeof(data_dir));
+                       strlcpy(dict_dir, aspell_dir, sizeof(dict_dir));
+                       strlcat(dict_dir, "\\dict", sizeof(dict_dir));
+
+                       pspell_config_replace(config, "data-dir", data_dir);
+                       pspell_config_replace(config, "dict-dir", dict_dir);
+               }
        }
 #endif