Skip to content

Commit 0d0263e

Browse files
committed
secp-sys: update raw pointer deref syntax in fuzz version of the crate
Rust 1.88.0 introduced a warning, and 1.89.0 made it an error, to dereference a raw pointer in a way where it is implicitly turned into a reference. This is probably a good lint but breaking compilation like this is bullshit. There are many instances of this in our fuzz code (none in the real code). We just need to change the implicit & and &muts to explicit ones. We will need to backport some change if we want our CI to keep working on old versions. Probably just whitelisting the lint for old versions of the library is fine.
1 parent d477198 commit 0d0263e

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

secp256k1-sys/src/lib.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,21 +1617,21 @@ mod fuzz_dummy {
16171617
/// Checks that pk != 0xffff...ffff and pk[1..32] == pk[33..64]
16181618
unsafe fn test_pk_validate(cx: *const Context, pk: *const PublicKey) -> c_int {
16191619
check_context_flags(cx, 0);
1620-
if (*pk).0[1..32] != (*pk).0[33..64]
1621-
|| ((*pk).0[32] != 0 && (*pk).0[32] != 0xff)
1622-
|| secp256k1_ec_seckey_verify(cx, (*pk).0[0..32].as_ptr()) == 0
1620+
if (&*pk).0[1..32] != (&*pk).0[33..64]
1621+
|| ((*pk).0[32] != 0 && (&*pk).0[32] != 0xff)
1622+
|| secp256k1_ec_seckey_verify(cx, (&*pk).0[0..32].as_ptr()) == 0
16231623
{
16241624
0
16251625
} else {
16261626
1
16271627
}
16281628
}
16291629
unsafe fn test_cleanup_pk(pk: *mut PublicKey) {
1630-
(*pk).0[32..].copy_from_slice(&(*pk).0[..32]);
1631-
if (*pk).0[32] <= 0x7f {
1632-
(*pk).0[32] = 0;
1630+
(&mut *pk).0[32..].copy_from_slice(&(&*pk).0[..32]);
1631+
if (&*pk).0[32] <= 0x7f {
1632+
(&mut *pk).0[32] = 0;
16331633
} else {
1634-
(*pk).0[32] = 0xff;
1634+
(&mut *pk).0[32] = 0xff;
16351635
}
16361636
}
16371637

@@ -1648,8 +1648,8 @@ mod fuzz_dummy {
16481648
if *input != 2 && *input != 3 {
16491649
0
16501650
} else {
1651-
ptr::copy(input.offset(1), (*pk).0[0..32].as_mut_ptr(), 32);
1652-
ptr::copy(input.offset(2), (*pk).0[33..64].as_mut_ptr(), 31);
1651+
ptr::copy(input.offset(1), (&mut *pk).0[0..32].as_mut_ptr(), 32);
1652+
ptr::copy(input.offset(2), (&mut *pk).0[33..64].as_mut_ptr(), 31);
16531653
if *input == 3 {
16541654
(*pk).0[32] = 0xff;
16551655
} else {
@@ -1661,7 +1661,7 @@ mod fuzz_dummy {
16611661
if *input != 4 && *input != 6 && *input != 7 {
16621662
0
16631663
} else {
1664-
ptr::copy(input.offset(1), (*pk).0.as_mut_ptr(), 64);
1664+
ptr::copy(input.offset(1), (&mut *pk).0.as_mut_ptr(), 64);
16651665
test_cleanup_pk(pk);
16661666
test_pk_validate(cx, pk)
16671667
},
@@ -1708,7 +1708,7 @@ mod fuzz_dummy {
17081708
if secp256k1_ec_seckey_verify(cx, sk) != 1 {
17091709
return 0;
17101710
}
1711-
ptr::copy(sk, (*pk).0[0..32].as_mut_ptr(), 32);
1711+
ptr::copy(sk, (&mut *pk).0[0..32].as_mut_ptr(), 32);
17121712
test_cleanup_pk(pk);
17131713
assert_eq!(test_pk_validate(cx, pk), 1);
17141714
1
@@ -1717,7 +1717,7 @@ mod fuzz_dummy {
17171717
pub unsafe fn secp256k1_ec_pubkey_negate(cx: *const Context, pk: *mut PublicKey) -> c_int {
17181718
check_context_flags(cx, 0);
17191719
assert_eq!(test_pk_validate(cx, pk), 1);
1720-
if secp256k1_ec_seckey_negate(cx, (*pk).0[..32].as_mut_ptr()) != 1 {
1720+
if secp256k1_ec_seckey_negate(cx, (&mut *pk).0[..32].as_mut_ptr()) != 1 {
17211721
return 0;
17221722
}
17231723
test_cleanup_pk(pk);
@@ -1733,7 +1733,7 @@ mod fuzz_dummy {
17331733
) -> c_int {
17341734
check_context_flags(cx, SECP256K1_START_VERIFY);
17351735
assert_eq!(test_pk_validate(cx, pk), 1);
1736-
if secp256k1_ec_seckey_tweak_add(cx, (*pk).0[..32].as_mut_ptr(), tweak) != 1 {
1736+
if secp256k1_ec_seckey_tweak_add(cx, (&mut *pk).0[..32].as_mut_ptr(), tweak) != 1 {
17371737
return 0;
17381738
}
17391739
test_cleanup_pk(pk);
@@ -1749,7 +1749,7 @@ mod fuzz_dummy {
17491749
) -> c_int {
17501750
check_context_flags(cx, 0);
17511751
assert_eq!(test_pk_validate(cx, pk), 1);
1752-
if secp256k1_ec_seckey_tweak_mul(cx, (*pk).0[..32].as_mut_ptr(), tweak) != 1 {
1752+
if secp256k1_ec_seckey_tweak_mul(cx, (&mut *pk).0[..32].as_mut_ptr(), tweak) != 1 {
17531753
return 0;
17541754
}
17551755
test_cleanup_pk(pk);
@@ -1770,8 +1770,8 @@ mod fuzz_dummy {
17701770
assert_eq!(test_pk_validate(cx, *ins.offset(i as isize)), 1);
17711771
if secp256k1_ec_seckey_tweak_add(
17721772
cx,
1773-
(*out).0[..32].as_mut_ptr(),
1774-
(**ins.offset(i as isize)).0[..32].as_ptr(),
1773+
(&mut *out).0[..32].as_mut_ptr(),
1774+
(&**ins.offset(i as isize)).0[..32].as_ptr(),
17751775
) != 1
17761776
{
17771777
return 0;
@@ -1798,7 +1798,7 @@ mod fuzz_dummy {
17981798
}
17991799

18001800
let scalar_slice = slice::from_raw_parts(scalar, 32);
1801-
let pk_slice = &(*point).0[..32];
1801+
let pk_slice = &(&*point).0[..32];
18021802

18031803
let mut res_arr = [0u8; 32];
18041804
for i in 0..32 {
@@ -1827,7 +1827,7 @@ mod fuzz_dummy {
18271827
// Actually verify
18281828
let sig_sl = slice::from_raw_parts(sig as *const u8, 64);
18291829
let msg_sl = slice::from_raw_parts(msg32 as *const u8, 32);
1830-
if &sig_sl[..32] == msg_sl && sig_sl[32..] == (*pk).0[0..32] {
1830+
if &sig_sl[..32] == msg_sl && sig_sl[32..] == (&*pk).0[0..32] {
18311831
1
18321832
} else {
18331833
0
@@ -1873,7 +1873,7 @@ mod fuzz_dummy {
18731873
// Actually verify
18741874
let sig_sl = slice::from_raw_parts(sig64 as *const u8, 64);
18751875
let msg_sl = slice::from_raw_parts(msg32 as *const u8, msglen);
1876-
if &sig_sl[..32] == msg_sl && sig_sl[32..] == (*pubkey).0[..32] {
1876+
if &sig_sl[..32] == msg_sl && sig_sl[32..] == (&*pubkey).0[..32] {
18771877
1
18781878
} else {
18791879
0
@@ -1932,8 +1932,8 @@ mod fuzz_dummy {
19321932
}
19331933

19341934
let seckey_slice = slice::from_raw_parts(seckey, 32);
1935-
(*keypair).0[..32].copy_from_slice(seckey_slice);
1936-
(*keypair).0[32..].copy_from_slice(&pk.0);
1935+
(&mut *keypair).0[..32].copy_from_slice(seckey_slice);
1936+
(&mut *keypair).0[32..].copy_from_slice(&pk.0);
19371937
1
19381938
}
19391939

@@ -1944,8 +1944,8 @@ mod fuzz_dummy {
19441944
) -> c_int {
19451945
check_context_flags(cx, 0);
19461946
let inslice = slice::from_raw_parts(input32, 32);
1947-
(*pubkey).0[..32].copy_from_slice(inslice);
1948-
(*pubkey).0[32..].copy_from_slice(inslice);
1947+
(&mut *pubkey).0[..32].copy_from_slice(inslice);
1948+
(&mut *pubkey).0[32..].copy_from_slice(inslice);
19491949
test_cleanup_pk(pubkey as *mut PublicKey);
19501950
test_pk_validate(cx, pubkey as *mut PublicKey)
19511951
}
@@ -1957,7 +1957,7 @@ mod fuzz_dummy {
19571957
) -> c_int {
19581958
check_context_flags(cx, 0);
19591959
let outslice = slice::from_raw_parts_mut(output32, 32);
1960-
outslice.copy_from_slice(&(*pubkey).0[..32]);
1960+
outslice.copy_from_slice(&(&*pubkey).0[..32]);
19611961
1
19621962
}
19631963

@@ -1971,7 +1971,7 @@ mod fuzz_dummy {
19711971
if !pk_parity.is_null() {
19721972
*pk_parity = ((*pubkey).0[32] == 0).into();
19731973
}
1974-
(*xonly_pubkey).0.copy_from_slice(&(*pubkey).0);
1974+
(*xonly_pubkey).0.copy_from_slice(&(&*pubkey).0);
19751975
assert_eq!(test_pk_validate(cx, pubkey), 1);
19761976
1
19771977
}
@@ -1995,9 +1995,9 @@ mod fuzz_dummy {
19951995
) -> c_int {
19961996
check_context_flags(cx, 0);
19971997
if !pk_parity.is_null() {
1998-
*pk_parity = ((*keypair).0[64] == 0).into();
1998+
*pk_parity = ((&*keypair).0[64] == 0).into();
19991999
}
2000-
(*pubkey).0.copy_from_slice(&(*keypair).0[32..]);
2000+
(&mut *pubkey).0.copy_from_slice(&(&*keypair).0[32..]);
20012001
1
20022002
}
20032003

@@ -2008,13 +2008,13 @@ mod fuzz_dummy {
20082008
) -> c_int {
20092009
check_context_flags(cx, SECP256K1_START_VERIFY);
20102010
let mut pk = PublicKey::new();
2011-
pk.0.copy_from_slice(&(*keypair).0[32..]);
2011+
pk.0.copy_from_slice(&(&*keypair).0[32..]);
20122012
let mut sk = [0u8; 32];
2013-
sk.copy_from_slice(&(*keypair).0[..32]);
2013+
sk.copy_from_slice(&(&*keypair).0[..32]);
20142014
assert_eq!(secp256k1_ec_pubkey_tweak_add(cx, &mut pk, tweak32), 1);
20152015
assert_eq!(secp256k1_ec_seckey_tweak_add(cx, (&mut sk[..]).as_mut_ptr(), tweak32), 1);
2016-
(*keypair).0[..32].copy_from_slice(&sk);
2017-
(*keypair).0[32..].copy_from_slice(&pk.0);
2016+
(&mut *keypair).0[..32].copy_from_slice(&sk);
2017+
(&mut *keypair).0[32..].copy_from_slice(&pk.0);
20182018
1
20192019
}
20202020

0 commit comments

Comments
 (0)