Skip to content
Langston Barrett edited this page Mar 8, 2019 · 4 revisions

SAW and OpenSSL

The following are a few things to keep in mind when using SAW with OpenSSL.

Memory management

As outlined in the manual, global variables are not automatically initialized. OpenSSL's memory management functions (e.g. CRYPTO_malloc, CRYPTO_free, etc.) use several globals. Here's how to initialize (some of) them in your SAWscript:

let init_global name = do {
  crucible_points_to (crucible_global name) (crucible_global_initializer name);
};

let my_spec = do {
    // Used in OpenSSL memory management functions
    init_global "allow_customize";
    init_global "malloc_debug_func";
    init_global "malloc_ex_func";
    init_global "malloc_func";

    // ...
}

Here's an example of an error you would see if one were uninitialized (saw was run with --verbose=5, --sim-verbose=5):

CRYPTO_malloc:
  $6 = resolveGlobal llvm_memory "malloc_debug_func" % 341:9
CRYPTO_malloc:
  $7 = load llvm_memory $6 bitvectorType 8 Alignment 3 % 341:9
Abort due to false assumption:
  Error during memory load: 
  Generic memory load error
  in CRYPTO_malloc at /build/openssl-1.0.2r/crypto/mem.c:341:9
Clone this wiki locally