Skip to content

Commit 3d60a18

Browse files
authored
Merge pull request #113 from jonasnick/fix-recovery-fuzz
Fix imports when using recovery with fuzztarget feature
2 parents 2d41612 + 0e6ff34 commit 3d60a18

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ script:
2929
- cargo build --verbose --no-default-features --features="serde"
3030
- cargo build --verbose --no-default-features --features="rand"
3131
- cargo build --verbose --no-default-features --features="rand serde recovery"
32+
- cargo build --verbose --no-default-features --features="fuzztarget recovery"
3233
- cargo build --verbose
3334
- cargo test --verbose
3435
- cargo build --release

src/ffi.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ pub type EcdhHashFn = unsafe extern "C" fn(
6060
#[derive(Clone, Debug)]
6161
#[repr(C)] pub struct Context(c_int);
6262

63+
#[cfg(feature = "fuzztarget")]
64+
impl Context {
65+
pub fn flags(&self) -> u32 {
66+
self.0 as u32
67+
}
68+
}
69+
6370
/// Library-internal representation of a Secp256k1 public key
6471
#[repr(C)]
6572
pub struct PublicKey([c_uchar; 64]);
@@ -250,9 +257,11 @@ extern "C" {
250257

251258
#[cfg(feature = "fuzztarget")]
252259
mod fuzz_dummy {
253-
use std::os::raw::{c_int, c_uchar, c_uint, c_void};
260+
extern crate std;
261+
use types::*;
254262
use ffi::*;
255-
use std::ptr;
263+
use self::std::ptr;
264+
use self::std::boxed::Box;
256265

257266
extern "C" {
258267
pub static secp256k1_ecdh_hash_function_default: EcdhHashFn;

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
#![cfg_attr(feature = "dev", feature(plugin))]
134134
#![cfg_attr(feature = "dev", plugin(clippy))]
135135

136-
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
136+
#![cfg_attr(all(not(test), not(fuzztarget), not(feature = "std")), no_std)]
137137
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
138138
#[cfg(all(test, feature = "unstable"))] extern crate test;
139139
#[cfg(any(test, feature = "rand"))] pub extern crate rand;

src/recovery/ffi.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ extern "C" {
6969

7070
#[cfg(feature = "fuzztarget")]
7171
mod fuzz_dummy {
72+
extern crate std;
73+
use types::*;
74+
use ffi::*;
75+
use self::std::ptr;
76+
use super::RecoverableSignature;
77+
7278
pub unsafe fn secp256k1_ecdsa_recoverable_signature_parse_compact(_cx: *const Context, _sig: *mut RecoverableSignature,
7379
_input64: *const c_uchar, _recid: c_int)
7480
-> c_int {
@@ -95,8 +101,8 @@ mod fuzz_dummy {
95101
_noncefn: NonceFn,
96102
_noncedata: *const c_void)
97103
-> c_int {
98-
assert!(!cx.is_null() && (*cx).0 as u32 & !(SECP256K1_START_NONE | SECP256K1_START_VERIFY | SECP256K1_START_SIGN) == 0);
99-
assert!((*cx).0 as u32 & SECP256K1_START_SIGN == SECP256K1_START_SIGN);
104+
assert!(!cx.is_null() && (*cx).flags() & !(SECP256K1_START_NONE | SECP256K1_START_VERIFY | SECP256K1_START_SIGN) == 0);
105+
assert!((*cx).flags() & SECP256K1_START_SIGN == SECP256K1_START_SIGN);
100106
if secp256k1_ec_seckey_verify(cx, sk) != 1 { return 0; }
101107
if *sk.offset(0) > 0x7f {
102108
(*sig).0[0] = 2;
@@ -116,3 +122,5 @@ mod fuzz_dummy {
116122
unimplemented!();
117123
}
118124
}
125+
#[cfg(feature = "fuzztarget")]
126+
pub use self::fuzz_dummy::*;

0 commit comments

Comments
 (0)