Skip to content
Snippets Groups Projects
Commit b5b37691 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Don't set cryptlib_initialized = true until the init is complete

is_crypt_initialized() does not depend on the once value.
parent 93d71feb
Branches
No related tags found
No related merge requests found
Pipeline #8638 failed
...@@ -310,7 +310,6 @@ static void internal_do_cryptInit(void) ...@@ -310,7 +310,6 @@ static void internal_do_cryptInit(void)
if ((ret = cryptInit()) == CRYPT_OK) { if ((ret = cryptInit()) == CRYPT_OK) {
cryptAddRandom(NULL, CRYPT_RANDOM_SLOWPOLL); cryptAddRandom(NULL, CRYPT_RANDOM_SLOWPOLL);
atexit(do_cryptEnd); atexit(do_cryptEnd);
cryptlib_initialized = true;
cryptInit_error = CRYPT_OK; cryptInit_error = CRYPT_OK;
} }
else { else {
...@@ -319,28 +318,24 @@ static void internal_do_cryptInit(void) ...@@ -319,28 +318,24 @@ static void internal_do_cryptInit(void)
ret = cryptGetAttribute(CRYPT_UNUSED, CRYPT_OPTION_INFO_MAJORVERSION, &maj); ret = cryptGetAttribute(CRYPT_UNUSED, CRYPT_OPTION_INFO_MAJORVERSION, &maj);
if (cryptStatusError(ret)) { if (cryptStatusError(ret)) {
cryptInit_error = ret; cryptInit_error = ret;
cryptlib_initialized = false;
cryptEnd(); cryptEnd();
return; return;
} }
ret = cryptGetAttribute(CRYPT_UNUSED, CRYPT_OPTION_INFO_MINORVERSION, &min); ret = cryptGetAttribute(CRYPT_UNUSED, CRYPT_OPTION_INFO_MINORVERSION, &min);
if (cryptStatusError(ret)) { if (cryptStatusError(ret)) {
cryptInit_error = ret; cryptInit_error = ret;
cryptlib_initialized = false;
cryptEnd(); cryptEnd();
return; return;
} }
ret = cryptGetAttribute(CRYPT_UNUSED, CRYPT_OPTION_INFO_STEPPING, &stp); ret = cryptGetAttribute(CRYPT_UNUSED, CRYPT_OPTION_INFO_STEPPING, &stp);
if (cryptStatusError(ret)) { if (cryptStatusError(ret)) {
cryptInit_error = ret; cryptInit_error = ret;
cryptlib_initialized = false;
cryptEnd(); cryptEnd();
return; return;
} }
tmp = (maj * 100) + (min * 10) + stp; tmp = (maj * 100) + (min * 10) + stp;
if (tmp != CRYPTLIB_VERSION) { if (tmp != CRYPTLIB_VERSION) {
cryptInit_error = CRYPT_ERROR_INVALID; cryptInit_error = CRYPT_ERROR_INVALID;
cryptlib_initialized = false;
cryptEnd(); cryptEnd();
if (asprintf(&cryptfail, "Incorrect cryptlib version %d (expected %d)", tmp, CRYPTLIB_VERSION) == -1) if (asprintf(&cryptfail, "Incorrect cryptlib version %d (expected %d)", tmp, CRYPTLIB_VERSION) == -1)
cryptfail = NULL; cryptfail = NULL;
...@@ -349,12 +344,12 @@ static void internal_do_cryptInit(void) ...@@ -349,12 +344,12 @@ static void internal_do_cryptInit(void)
ret = cryptGetAttributeString(CRYPT_UNUSED, CRYPT_OPTION_INFO_PATCHES, patches, &stp); ret = cryptGetAttributeString(CRYPT_UNUSED, CRYPT_OPTION_INFO_PATCHES, patches, &stp);
if (cryptStatusError(ret) || stp != 32 || memcmp(patches, CRYPTLIB_PATCHES, 32) != 0) { if (cryptStatusError(ret) || stp != 32 || memcmp(patches, CRYPTLIB_PATCHES, 32) != 0) {
cryptInit_error = ret; cryptInit_error = ret;
cryptlib_initialized = false;
cryptEnd(); cryptEnd();
if (asprintf(&cryptfail, "Incorrect cryptlib patch set %.32s (expected %s)", patches, CRYPTLIB_PATCHES) == -1) if (asprintf(&cryptfail, "Incorrect cryptlib patch set %.32s (expected %s)", patches, CRYPTLIB_PATCHES) == -1)
cryptfail = NULL; cryptfail = NULL;
return; return;
} }
cryptlib_initialized = true;
return; return;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment