Skip to content

Commit

Permalink
Remove code which may cause segfault from the tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ni4 committed Jul 26, 2024
1 parent 41cf5f0 commit bc71992
Showing 1 changed file with 0 additions and 36 deletions.
36 changes: 0 additions & 36 deletions src/tests/key-protect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,49 +261,13 @@ TEST_F(rnp_tests, test_key_protect_sec_data)
memcpy(raw_ssub, ssub.pkt().sec_data, 32);
pgp_key_pkt_t *skeypkt;
pgp_key_pkt_t *ssubpkt;
#if defined(__has_feature)
#if !__has_feature(address_sanitizer)
/* copy keys and delete, making sure secret data is wiped*/
pgp_key_t *skeycp = new pgp_key_t(skey);
pgp_key_t *ssubcp = new pgp_key_t(ssub);
uint8_t * raw_skey_ptr = skeycp->pkt().sec_data;
uint8_t * raw_ssub_ptr = ssubcp->pkt().sec_data;
assert_int_equal(memcmp(raw_skey, raw_skey_ptr, 32), 0);
assert_int_equal(memcmp(raw_ssub, raw_ssub_ptr, 32), 0);
delete skeycp;
delete ssubcp;
assert_int_not_equal(memcmp(raw_skey, raw_skey_ptr, 32), 0);
assert_int_not_equal(memcmp(raw_ssub, raw_ssub_ptr, 32), 0);
/* do the same with key packet */
skeypkt = new pgp_key_pkt_t(skey.pkt());
ssubpkt = new pgp_key_pkt_t(ssub.pkt());
raw_skey_ptr = skeypkt->sec_data;
raw_ssub_ptr = ssubpkt->sec_data;
assert_int_equal(memcmp(raw_skey, raw_skey_ptr, 32), 0);
assert_int_equal(memcmp(raw_ssub, raw_ssub_ptr, 32), 0);
delete skeypkt;
delete ssubpkt;
assert_int_not_equal(memcmp(raw_skey, raw_skey_ptr, 32), 0);
assert_int_not_equal(memcmp(raw_ssub, raw_ssub_ptr, 32), 0);
/* save original pointers */
raw_skey_ptr = skey.pkt().sec_data;
raw_ssub_ptr = ssub.pkt().sec_data;
#endif
#endif

/* protect key and subkey */
pgp_password_provider_t pprov(string_copy_password_callback, (void *) "password");
rnp_key_protection_params_t prot = {};
assert_true(skey.protect(prot, pprov, global_ctx));
assert_true(ssub.protect(prot, pprov, global_ctx));
assert_int_not_equal(memcmp(raw_skey, skey.pkt().sec_data, 32), 0);
assert_int_not_equal(memcmp(raw_ssub, ssub.pkt().sec_data, 32), 0);
#if defined(__has_feature)
#if !__has_feature(address_sanitizer)
assert_int_not_equal(memcmp(raw_skey, raw_skey_ptr, 32), 0);
assert_int_not_equal(memcmp(raw_ssub, raw_ssub_ptr, 32), 0);
#endif
#endif
/* make sure rawpkt is also protected */
skeypkt = new pgp_key_pkt_t();
pgp_source_t memsrc = {};
Expand Down

0 comments on commit bc71992

Please sign in to comment.