Skip to content

Commit

Permalink
Updated the fuzzing dummy functions
Browse files Browse the repository at this point in the history
  • Loading branch information
elichai committed Jul 4, 2019
1 parent 08655df commit 5dd9dcc
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ mod fuzz_dummy {
use ffi::*;
use self::std::ptr;
use self::std::boxed::Box;
use std::mem;

extern "C" {
pub static secp256k1_ecdh_hash_function_default: EcdhHashFn;
Expand All @@ -335,20 +336,31 @@ mod fuzz_dummy {

// Contexts
/// Creates a dummy context, tracking flags to ensure proper calling semantics
pub unsafe fn secp256k1_context_create(flags: c_uint) -> *mut Context {
pub unsafe fn secp256k1_context_preallocated_create(_ptr: *mut c_void, flags: c_uint) -> *mut Context {
let b = Box::new(Context(flags as i32));
Box::into_raw(b)
}

/// Return dummy size of context struct.
pub unsafe fn secp256k1_context_preallocated_size(_flags: c_uint) -> usize {
mem::size_of::<Context>()
}

/// Return dummy size of context struct.
pub unsafe fn secp256k1_context_preallocated_clone_size(cx: *mut Context) -> usize {
mem::size_of::<Context>()
}

/// Copies a dummy context
pub unsafe fn secp256k1_context_clone(cx: *mut Context) -> *mut Context {
let b = Box::new(Context((*cx).0));
Box::into_raw(b)
pub unsafe fn secp256k1_context_preallocated_clone(cx: *const Context, prealloc: *mut c_void) -> *mut Context {
let ret = prealloc as *mut Context;
*ret = (*cx).clone();
ret
}

/// Frees a dummy context
pub unsafe fn secp256k1_context_destroy(cx: *mut Context) {
Box::from_raw(cx);
/// "Destroys" a dummy context
pub unsafe fn secp256k1_context_preallocated_destroy(cx: *mut Context) {
(*cx).0 = 0;
}

/// Asserts that cx is properly initialized
Expand Down

0 comments on commit 5dd9dcc

Please sign in to comment.