mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 12:11:59 +00:00
Work around UB in LMDB bindings (#6211)
* Work around UB in LMDB bindings
This commit is contained in:
@@ -165,8 +165,12 @@ impl<'env> Cursor<'env> {
|
||||
}
|
||||
|
||||
pub fn get_current(&mut self) -> Result<Option<(Key<'env>, Value<'env>)>, Error> {
|
||||
// FIXME: lmdb has an extremely broken API which can mutate the SHARED REFERENCE
|
||||
// `value` after `get_current` is called. We need to convert it to a Vec here in order
|
||||
// to avoid `value` changing after another cursor operation. I think this represents a bug
|
||||
// in the LMDB bindings, as shared references should be immutable.
|
||||
if let Some((Some(key), value)) = self.cursor.get(None, None, MDB_GET_CURRENT).optional()? {
|
||||
Ok(Some((Cow::Borrowed(key), Cow::Borrowed(value))))
|
||||
Ok(Some((Cow::Borrowed(key), Cow::Owned(value.to_vec()))))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user