From 49f0cc1c46eebf507ebe038da246e4e547eadb40 Mon Sep 17 00:00:00 2001 From: Elichai Turkel Date: Thu, 4 Jul 2019 19:03:13 -0400 Subject: [PATCH] Updated the fuzzing dummy functions --- src/context.rs | 5 ++++- src/ffi.rs | 27 +++++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/context.rs b/src/context.rs index 4eb5e815c..aa35d1e5f 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,5 +1,8 @@ use core::marker::PhantomData; -use {ffi, types::{c_uint, c_void}, Error, Secp256k1}; +use ffi; +use types::{c_uint, c_void}; +use Error; +use Secp256k1; #[cfg(feature = "std")] pub use self::std_only::*; diff --git a/src/ffi.rs b/src/ffi.rs index ba136bb7b..42062f7cb 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -324,7 +324,7 @@ mod fuzz_dummy { extern crate std; use types::*; use ffi::*; - use self::std::ptr; + use self::std::{ptr, mem}; use self::std::boxed::Box; extern "C" { @@ -335,20 +335,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::() + } + + /// Return dummy size of context struct. + pub unsafe fn secp256k1_context_preallocated_clone_size(cx: *mut Context) -> usize { + mem::size_of::() + } + /// 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