Commit dbb6f8cc authored by Milan Broz's avatar Milan Broz
Browse files

Wipe all function pointers on tokens unload

Just a code hardening.
parent f27ceb86
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -219,18 +219,24 @@ crypt_token_load_external(struct crypt_device *cd, const char *name, struct cryp

void crypt_token_unload_external_all(struct crypt_device *cd)
{
	struct crypt_token_handler_v2 *token;
	int i;

	for (i = LUKS2_TOKENS_MAX - 1; i >= 0; i--) {
		if (token_handlers[i].version < 2)
			continue;

		log_dbg(cd, "Unloading %s token handler.", token_handlers[i].u.v2.name);
		token = &token_handlers[i].u.v2;

		log_dbg(cd, "Unloading %s token handler.", token->name);

		free(CONST_CAST(void *)token_handlers[i].u.v2.name);
		free(CONST_CAST(void *)token->name);

		if (dlclose(CONST_CAST(void *)token_handlers[i].u.v2.dlhandle))
		if (dlclose(token->dlhandle))
			log_dbg(cd, "%s", dlerror());

		memset(token, 0, sizeof(*token));
		token_handlers[i].version = 0;
	}
}