Skip to content

Commit

Permalink
crypto: Fix double free in bd_crypto_luks_remove_key
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechtrefny committed Apr 3, 2024
1 parent 8aafe98 commit 1b6d24e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/plugins/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,6 @@ gboolean bd_crypto_luks_remove_key (const gchar *device, BDCryptoKeyslotContext
return FALSE;
}

crypt_safe_free (key_buf);
crypt_free (cd);
bd_utils_report_finished (progress_id, "Completed");
return TRUE;
Expand Down
6 changes: 6 additions & 0 deletions tests/crypto_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,9 @@ def _remove_key(self, create_fn):
succ = BlockDev.crypto_luks_add_key(self.loop_dev, ctx, nctx2)
self.assertTrue(succ)

nctx3 = BlockDev.CryptoKeyslotContext(keyfile=self.keyfile)
succ = BlockDev.crypto_luks_add_key(self.loop_dev, ctx, nctx3)

with self.assertRaises(GLib.GError):
wctx = BlockDev.CryptoKeyslotContext(passphrase="wrong-passphrase")
BlockDev.crypto_luks_remove_key(self.loop_dev, wctx)
Expand All @@ -534,6 +537,9 @@ def _remove_key(self, create_fn):
succ = BlockDev.crypto_luks_remove_key(self.loop_dev, nctx2)
self.assertTrue(succ)

succ = BlockDev.crypto_luks_remove_key(self.loop_dev, nctx3)
self.assertTrue(succ)

@tag_test(TestTags.SLOW)
def test_luks_remove_key(self):
self._remove_key(self._luks_format)
Expand Down

0 comments on commit 1b6d24e

Please sign in to comment.