Skip to content

Commit b5c6021

Browse files
committed
prevent null access in value blob. credit: github.com/asg017/pull/23
1 parent 8e34664 commit b5c6021

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/api.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,13 @@ pub fn mprintf(base: &str) -> Result<*mut c_char, MprintfError> {
117117
/// Returns the [`sqlite3_value_blob`](https://www.sqlite.org/c3ref/value_blob.html) result
118118
/// from the given sqlite3_value, as a u8 slice.
119119
pub fn value_blob<'a>(value: &*mut sqlite3_value) -> &'a [u8] {
120-
let n = value_bytes(value);
121-
let b = unsafe { sqlite3ext_value_blob(value.to_owned()) };
122-
return unsafe { from_raw_parts(b.cast::<u8>(), n as usize) };
120+
match value_bytes(value) {
121+
0 => &[],
122+
n => {
123+
let b = unsafe { sqlite3ext_value_blob(value.to_owned()) };
124+
unsafe { from_raw_parts(b.cast::<u8>(), n as usize) }
125+
}
126+
}
123127
}
124128

125129
/// Returns the [`sqlite3_value_bytes`](https://www.sqlite.org/c3ref/value_blob.html) result

0 commit comments

Comments
 (0)