Skip to content

MASKS_ALL and MASKS_BIT may leak the pointed Vec<BigUint>. #1

@labyrinth-ssr

Description

@labyrinth-ssr

synthir/src/emulator.rs

Lines 29 to 30 in 98047d1

MASKS_ALL = Box::into_raw(v_a);
MASKS_BIT = Box::into_raw(v_b);

with Box::into_raw(), the pointee is on the heap. Multiple assignments will cause leak of the old value.

Probable fix is like:
If init_masks() should only be called once, adding an Atomic to guarantee assigning only once.

const UNINITIALIZED: usize = 0;
const INITIALIZING: usize = 1;
const INITIALIZED: usize = 2;
static GLOBAL_INIT: AtomicUsize = AtomicUsize::new(UNINITIALIZED);
pub struct SetGlobalDefaultError {
    _no_construct: (),
}

// in `init_masks()`
           if GLOBAL_INIT
                .compare_exchange(
                    UNINITIALIZED,
                    INITIALIZING,
                    Ordering::SeqCst,
                    Ordering::SeqCst,
                )
                .is_ok()
            {
                MASKS_ALL = Box::into_raw(v_a);
                MASKS_BIT = Box::into_raw(v_b);
            }
    }
} 

Otherwise add the else branch:

           else {
              drop(Box::from_raw(MASKS_ALL));
              drop(Box::from_raw(MASKS_BIT));
              MASKS_ALL = Box::into_raw(v_a);
              MASKS_BIT = Box::into_raw(v_b);
          }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions