Skip to content

Commit cb9fef1

Browse files
committed
Fix xFullPathname implement
1 parent d04c448 commit cb9fef1

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

sqlite-wasm-rs/src/shim/vfs/memory.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,16 @@ unsafe extern "C" fn xFullPathname(
156156
nOut: ::std::os::raw::c_int,
157157
zOut: *mut ::std::os::raw::c_char,
158158
) -> ::std::os::raw::c_int {
159-
zName.copy_to(zOut, nOut as usize);
159+
if zName.is_null() || zOut.is_null() {
160+
return SQLITE_CANTOPEN;
161+
}
162+
let len = CStr::from_ptr(zName).count_bytes() + 1;
163+
164+
if len > nOut as usize {
165+
return SQLITE_CANTOPEN;
166+
}
167+
zName.copy_to(zOut, len);
168+
160169
SQLITE_OK
161170
}
162171

@@ -286,7 +295,7 @@ unsafe extern "C" fn xCheckReservedLock(
286295
}
287296

288297
unsafe extern "C" fn xFileControl(
289-
_pVfs: *mut sqlite3_file,
298+
_pFile: *mut sqlite3_file,
290299
_op: ::std::os::raw::c_int,
291300
_pArg: *mut ::std::os::raw::c_void,
292301
) -> ::std::os::raw::c_int {

sqlite-wasm-rs/src/shim/vfs/sahpool.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,17 @@ unsafe extern "C" fn xFullPathname(
833833
nOut: ::std::os::raw::c_int,
834834
zOut: *mut ::std::os::raw::c_char,
835835
) -> ::std::os::raw::c_int {
836-
zName.copy_to(zOut, nOut as usize);
836+
if zName.is_null() || zOut.is_null() {
837+
return SQLITE_CANTOPEN;
838+
}
839+
let len = CStr::from_ptr(zName).count_bytes() + 1;
840+
841+
if len > nOut as usize {
842+
return SQLITE_CANTOPEN;
843+
}
844+
845+
zName.copy_to(zOut, len);
846+
837847
SQLITE_OK
838848
}
839849

0 commit comments

Comments
 (0)