Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify impl of read table properties #668

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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
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