summaryrefslogtreecommitdiff
path: root/ext/standard/php_crypt_r.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/php_crypt_r.c')
-rw-r--r--ext/standard/php_crypt_r.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/ext/standard/php_crypt_r.c b/ext/standard/php_crypt_r.c
index 3d9d0229d..5e2d851de 100644
--- a/ext/standard/php_crypt_r.c
+++ b/ext/standard/php_crypt_r.c
@@ -1,4 +1,4 @@
-/* $Id: php_crypt_r.c 293036 2010-01-03 09:23:27Z sebastian $ */
+/* $Id: php_crypt_r.c 300511 2010-06-17 10:22:03Z pajoye $ */
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
@@ -42,7 +42,11 @@
# include <Wincrypt.h>
#endif
-#include <signal.h>
+#ifdef HAVE_ATOMIC_H /* Solaris 10 defines atomic API within */
+# include <atomic.h>
+#else
+# include <signal.h>
+#endif
#include "php_crypt_r.h"
#include "crypt_freesec.h"
@@ -75,17 +79,28 @@ void php_shutdown_crypt_r()
void _crypt_extended_init_r(void)
{
+#ifdef PHP_WIN32
+ LONG volatile initialized = 0;
+#elif defined(HAVE_ATOMIC_H) /* Solaris 10 defines atomic API within */
+ volatile unsigned int initialized = 0;
+#else
static volatile sig_atomic_t initialized = 0;
+#endif
#ifdef ZTS
tsrm_mutex_lock(php_crypt_extended_init_lock);
#endif
- if (initialized) {
- return;
- } else {
+ if (!initialized) {
+#ifdef PHP_WIN32
+ InterlockedIncrement(&initialized);
+#elif (defined(__GNUC__) && (__GNUC__ >= 4 && __GNUC_MINOR >= 2))
+ __sync_fetch_and_add(&initialized, 1);
+#elif defined(HAVE_ATOMIC_H) /* Solaris 10 defines atomic API within */
+ membar_producer();
+ atomic_add_int(&initialized, 1);
+#endif
_crypt_extended_init();
- initialized = 1;
}
#ifdef ZTS
tsrm_mutex_unlock(php_crypt_extended_init_lock);
@@ -212,9 +227,7 @@ char * php_md5_crypt_r(const char *pw, const char *salt, char *out) {
strcat_s(passwd, MD5_HASH_MAX_LEN, "$");
#else
/* VC6 version doesn't have strcat_s or strncpy_s */
- if (strncpy(passwd + MD5_MAGIC_LEN, sp, sl + 1) < sl) {
- goto _destroyCtx1;
- }
+ strncpy(passwd + MD5_MAGIC_LEN, sp, sl + 1);
strcat(passwd, "$");
#endif
dwHashLen = 16;