]> granicus.if.org Git - php/commitdiff
Fix bug: #8834. Now there should be more random salts..
authorfoobar <sniper@php.net>
Sun, 6 May 2001 16:54:27 +0000 (16:54 +0000)
committerfoobar <sniper@php.net>
Sun, 6 May 2001 16:54:27 +0000 (16:54 +0000)
ext/standard/basic_functions.c
ext/standard/crypt.c
ext/standard/lcg.c
ext/standard/php_crypt.h
ext/standard/php_lcg.h

index 4063d78468ca458a298365a2e394dc290dec2cf5..2eb15a196467bb7d79e4cdee8d60e077d52f789b 100644 (file)
@@ -747,7 +747,6 @@ PHP_MINIT_FUNCTION(basic)
        PHP_MINIT(file)(INIT_FUNC_ARGS_PASSTHRU);
        PHP_MINIT(pack)(INIT_FUNC_ARGS_PASSTHRU);
        PHP_MINIT(browscap)(INIT_FUNC_ARGS_PASSTHRU);
-       PHP_MINIT(lcg)(INIT_FUNC_ARGS_PASSTHRU);
 #if defined(HAVE_LOCALECONV) && defined(ZTS)
        PHP_MINIT(localeconv)(INIT_FUNC_ARGS_PASSTHRU);
 #endif
@@ -834,6 +833,11 @@ PHP_RINIT_FUNCTION(basic)
 #endif
        BG(user_shutdown_function_names)=NULL;
 
+#ifdef HAVE_CRYPT
+       PHP_RINIT(crypt)(INIT_FUNC_ARGS_PASSTHRU);
+#endif
+
+       PHP_RINIT(lcg)(INIT_FUNC_ARGS_PASSTHRU);
        PHP_RINIT(head)(INIT_FUNC_ARGS_PASSTHRU);
        PHP_RINIT(filestat)(INIT_FUNC_ARGS_PASSTHRU);
        PHP_RINIT(syslog)(INIT_FUNC_ARGS_PASSTHRU);
index 41f35cd31bfee8f8f2c9c31feb4c36804e194daa..011242acc0eb9c742bc14c9b995bb5abc107c69d 100644 (file)
@@ -89,6 +89,7 @@ extern char *crypt(char *__key,char *__salt);
 
 #define PHP_CRYPT_RAND php_rand()
 
+static int php_crypt_rand_seeded=0;
 
 PHP_MINIT_FUNCTION(crypt)
 {
@@ -102,11 +103,20 @@ PHP_MINIT_FUNCTION(crypt)
        REGISTER_LONG_CONSTANT("CRYPT_MD5", PHP_MD5_CRYPT, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("CRYPT_BLOWFISH", PHP_BLOWFISH_CRYPT, CONST_CS | CONST_PERSISTENT);
 
-       php_srand(time(0) * getpid() * (php_combined_lcg() * 10000.0));
+       return SUCCESS;
+}
+
 
+PHP_RINIT_FUNCTION(crypt)
+{
+       if(!php_crypt_rand_seeded) {
+               php_srand(time(0) * getpid() * (php_combined_lcg() * 10000.0));
+               php_crypt_rand_seeded=1;
+       } 
        return SUCCESS;
 }
 
+
 static unsigned char itoa64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 
 static void php_to64(char *s, long v, int n)   {
index be43a77124de253f006c7b5c3f4d850ad5343729..31321a6c81adf8ff9c97bb07a189b48cccba7292 100644 (file)
@@ -31,6 +31,8 @@ int lcg_globals_id;
 static php_lcg_globals lcg_globals;
 #endif
 
+static int php_lcg_initialized = 0;
+
 #ifdef PHP_WIN32
 #include <process.h>
 #endif
@@ -71,13 +73,16 @@ static void lcg_init_globals(LCGLS_D)
 #endif
 }
 
-PHP_MINIT_FUNCTION(lcg)
+PHP_RINIT_FUNCTION(lcg)
 {
+       if (!php_lcg_initialized) {
 #ifdef ZTS
-       lcg_globals_id = ts_allocate_id(sizeof(php_lcg_globals), (ts_allocate_ctor) lcg_init_globals, NULL);
+               lcg_globals_id = ts_allocate_id(sizeof(php_lcg_globals), (ts_allocate_ctor) lcg_init_globals, NULL);
 #else
-       lcg_init_globals();
+               lcg_init_globals();
 #endif
+               php_lcg_initialized = 1;
+       }
        return SUCCESS;
 }
 
index e6c6db1841089ac5e3fca151018dfe79bb17e923..4869ccf43e151e9b214a936510c801459b581815 100644 (file)
@@ -26,6 +26,7 @@
 PHP_FUNCTION(crypt);
 #if HAVE_CRYPT
 extern PHP_MINIT_FUNCTION(crypt);
+extern PHP_RINIT_FUNCTION(crypt);
 #endif
 
 #endif
index 2d88e582e6d24c6baf9b9c7c246122f8221349af..a6d8b0c0a4a9e10c159312edbc678e6e9194e8b7 100644 (file)
@@ -28,7 +28,7 @@ typedef struct {
 
 double php_combined_lcg(void);
 PHP_FUNCTION(lcg_value);
-PHP_MINIT_FUNCTION(lcg);
+PHP_RINIT_FUNCTION(lcg);
 
 #ifdef ZTS
 #define LCGLS_D php_lcg_globals *lcg_globals