Skip to content

Conversation

@Connor1996
Copy link
Member

@Connor1996 Connor1996 commented Nov 16, 2021

Rudra complains about the potential double-free issue https://paper.seebug.org/1728/#05-panic-safety-double-free-rustsec-2021-0011, so simplify it to avoid using mem::forgot

// Warning (UnsafeDataflow:/ReadFlow): Potential unsafe dataflow issue in 
// `rocksdb::SstFileReader::read_table_properties::callback`
// -> src/rocksdb.rs:2330:9: 2338:10
extern "C" fn callback<F: FnOnce(&TableProperties)>(
            ctx: *mut c_void,
            ptr: *const crocksdb_ffi::DBTableProperties,
        ) {
            unsafe {
                let caller = ptr::read(ctx as *mut F);
                caller(TableProperties::from_ptr(ptr));
            }
        }

@Connor1996 Connor1996 requested a review from BusyJay November 16, 2021 12:29
const crocksdb_sstfilereader_t* reader) {
auto props = reader->rep->GetTableProperties();
cb(ctx, reinterpret_cast<const crocksdb_table_properties_t*>(props.get()));
return reinterpret_cast<const crocksdb_table_properties_t*>(props.get());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the pointer still valid when props is dropped?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's a shared ptr from TableReader. In the context of read_table_properties, TableReader is promised not to be dropped.

@Connor1996
Copy link
Member Author

/test

@Connor1996
Copy link
Member Author

/build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants