Skip to content

Commit 8de8861

Browse files
Merge pull request #2563 from tnull/2023-09-kvstore-followups
`KVStore` upstreaming followups
2 parents 448b191 + aeaed62 commit 8de8861

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lightning-persister/src/fs_store.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ macro_rules! call {
2626
}
2727

2828
#[cfg(target_os = "windows")]
29-
fn path_to_windows_str<T: AsRef<OsStr>>(path: T) -> Vec<u16> {
29+
fn path_to_windows_str<T: AsRef<OsStr>>(path: &T) -> Vec<u16> {
3030
path.as_ref().encode_wide().chain(Some(0)).collect()
3131
}
3232

@@ -164,8 +164,8 @@ impl KVStore for FilesystemStore {
164164
let res = if dest_file_path.exists() {
165165
call!(unsafe {
166166
windows_sys::Win32::Storage::FileSystem::ReplaceFileW(
167-
path_to_windows_str(dest_file_path.clone()).as_ptr(),
168-
path_to_windows_str(tmp_file_path).as_ptr(),
167+
path_to_windows_str(&dest_file_path).as_ptr(),
168+
path_to_windows_str(&tmp_file_path).as_ptr(),
169169
std::ptr::null(),
170170
windows_sys::Win32::Storage::FileSystem::REPLACEFILE_IGNORE_MERGE_ERRORS,
171171
std::ptr::null_mut() as *const core::ffi::c_void,
@@ -175,8 +175,8 @@ impl KVStore for FilesystemStore {
175175
} else {
176176
call!(unsafe {
177177
windows_sys::Win32::Storage::FileSystem::MoveFileExW(
178-
path_to_windows_str(tmp_file_path).as_ptr(),
179-
path_to_windows_str(dest_file_path.clone()).as_ptr(),
178+
path_to_windows_str(&tmp_file_path).as_ptr(),
179+
path_to_windows_str(&dest_file_path).as_ptr(),
180180
windows_sys::Win32::Storage::FileSystem::MOVEFILE_WRITE_THROUGH
181181
| windows_sys::Win32::Storage::FileSystem::MOVEFILE_REPLACE_EXISTING,
182182
)
@@ -263,8 +263,8 @@ impl KVStore for FilesystemStore {
263263

264264
call!(unsafe {
265265
windows_sys::Win32::Storage::FileSystem::MoveFileExW(
266-
path_to_windows_str(dest_file_path).as_ptr(),
267-
path_to_windows_str(trash_file_path.clone()).as_ptr(),
266+
path_to_windows_str(&dest_file_path).as_ptr(),
267+
path_to_windows_str(&trash_file_path).as_ptr(),
268268
windows_sys::Win32::Storage::FileSystem::MOVEFILE_WRITE_THROUGH
269269
| windows_sys::Win32::Storage::FileSystem::MOVEFILE_REPLACE_EXISTING,
270270
)

lightning/src/util/persist.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ where
216216
for stored_key in kv_store.list(
217217
CHANNEL_MONITOR_PERSISTENCE_NAMESPACE, CHANNEL_MONITOR_PERSISTENCE_SUB_NAMESPACE)?
218218
{
219+
if stored_key.len() < 66 {
220+
return Err(io::Error::new(
221+
io::ErrorKind::InvalidData,
222+
"Stored key has invalid length"));
223+
}
224+
219225
let txid = Txid::from_hex(stored_key.split_at(64).0).map_err(|_| {
220226
io::Error::new(io::ErrorKind::InvalidData, "Invalid tx ID in stored key")
221227
})?;

0 commit comments

Comments
 (0)