diff options
| author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:37:27 -0400 |
|---|---|---|
| committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:37:27 -0400 |
| commit | 2d4e5b09576bb4f0ba716cc82cdf29ea04d9184b (patch) | |
| tree | 41ccc042009cba53e4ce43e727fcba4c1cfbf7f3 /ext/pspell | |
| parent | d29a4fd2dd3b5d4cf6e80b602544d7b71d794e76 (diff) | |
| download | php-upstream/5.2.2.tar.gz | |
Imported Upstream version 5.2.2upstream/5.2.2
Diffstat (limited to 'ext/pspell')
| -rw-r--r-- | ext/pspell/php_pspell.h | 4 | ||||
| -rw-r--r-- | ext/pspell/pspell.c | 96 |
2 files changed, 51 insertions, 49 deletions
diff --git a/ext/pspell/php_pspell.h b/ext/pspell/php_pspell.h index 8114cf3ff..416507486 100644 --- a/ext/pspell/php_pspell.h +++ b/ext/pspell/php_pspell.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_pspell.h,v 1.15.2.1.2.2 2006/08/14 20:08:17 nlopess Exp $ */ +/* $Id: php_pspell.h,v 1.15.2.1.2.3 2007/01/01 09:36:05 sebastian Exp $ */ #ifndef _PSPELL_H #define _PSPELL_H diff --git a/ext/pspell/pspell.c b/ext/pspell/pspell.c index 51fc0b12c..921bf26aa 100644 --- a/ext/pspell/pspell.c +++ b/ext/pspell/pspell.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pspell.c,v 1.45.2.4.2.2 2006/08/14 20:08:18 nlopess Exp $ */ +/* $Id: pspell.c,v 1.45.2.4.2.7 2007/02/24 02:17:25 helly Exp $ */ #define IS_EXT_MODULE @@ -186,15 +186,19 @@ static PHP_FUNCTION(pspell_new) * pointing to the location of the dictionaries */ if(0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) { - RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen); + LONG result; + dwLen = sizeof(aspell_dir) - 1; + 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 @@ -247,6 +251,7 @@ static PHP_FUNCTION(pspell_new) if(pspell_error_number(ret) != 0){ php_error_docref(NULL TSRMLS_CC, E_WARNING, "PSPELL couldn't open the dictionary. reason: %s ", pspell_error_message(ret)); + delete_pspell_manager(ret); RETURN_FALSE; } @@ -289,25 +294,31 @@ static PHP_FUNCTION(pspell_new_personal) * pointing to the location of the dictionaries */ if(0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) { - RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen); + LONG result; + dwLen = sizeof(aspell_dir) - 1; + 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 convert_to_string_ex(personal); if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_PP(personal), NULL, CHECKUID_CHECK_FILE_AND_DIR))) { + delete_pspell_config(config); RETURN_FALSE; } if (php_check_open_basedir(Z_STRVAL_PP(personal) TSRMLS_CC)) { + delete_pspell_config(config); RETURN_FALSE; } @@ -363,6 +374,7 @@ static PHP_FUNCTION(pspell_new_personal) if(pspell_error_number(ret) != 0){ php_error_docref(NULL TSRMLS_CC, E_WARNING, "PSPELL couldn't open the dictionary. reason: %s ", pspell_error_message(ret)); + delete_pspell_manager(ret); RETURN_FALSE; } @@ -396,6 +408,7 @@ static PHP_FUNCTION(pspell_new_config) if(pspell_error_number(ret) != 0){ php_error_docref(NULL TSRMLS_CC, E_WARNING, "PSPELL couldn't open the dictionary. reason: %s ", pspell_error_message(ret)); + delete_pspell_manager(ret); RETURN_FALSE; } @@ -641,17 +654,21 @@ static PHP_FUNCTION(pspell_config_create) /* If aspell was installed using installer, we should have a key * pointing to the location of the dictionaries */ - if(0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) { - 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(0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) { + LONG result; + dwLen = sizeof(aspell_dir) - 1; + result = RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen); + RegCloseKey(hkey); + 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 convert_to_string_ex(language); @@ -751,8 +768,7 @@ static PHP_FUNCTION(pspell_config_ignore) zval **conf, **pignore; int argc; - int loc = PSPELL_LARGEST_WORD; - char ignore_str[PSPELL_LARGEST_WORD + 1]; + char ignore_str[MAX_LENGTH_OF_LONG + 1]; long ignore = 0L; PspellConfig *config; @@ -767,23 +783,9 @@ static PHP_FUNCTION(pspell_config_ignore) convert_to_long_ex(pignore); ignore = Z_LVAL_PP(pignore); - /* The following is a very hackish way to convert a long to a string - (actually only the numbers 0-999 will get converted properly, but that should - be sufficient). If anyone knows of a better way to convert an integer to a string, - please, fix it.*/ - ignore_str[loc] = '\0'; - while(ignore > 0){ - if(loc == 0){ - break; - } - ignore_str[--loc] = '0' + (ignore % 10); - ignore /= 10; - } - if(ignore_str[loc] == '\0'){ - ignore_str[--loc] = '0'; - } + snprintf(ignore_str, sizeof(ignore_str), "%ld", ignore); - pspell_config_replace(config, "ignore", &ignore_str[loc]); + pspell_config_replace(config, "ignore", ignore_str); RETURN_TRUE; } /* }}} */ |
