Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit f7669af

Browse files
committed
treat empty location in uri invalid, fix #49
1 parent 0cf14cd commit f7669af

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/volume/storage/mem/mem.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct MemStorage {
1919
}
2020

2121
impl MemStorage {
22-
pub fn new() -> Self {
22+
pub fn new(_loc: &str) -> Self {
2323
MemStorage {
2424
super_blk_map: HashMap::new(),
2525
wal_map: HashMap::new(),

src/volume/storage/storage.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ fn parse_uri(uri: &str) -> Result<Box<dyn Storable>> {
2525

2626
// extract storage string
2727
let idx = uri.find("://").ok_or(Error::InvalidUri)?;
28-
let part = &uri[..idx];
28+
let loc = &uri[idx + 3..];
29+
if loc.is_empty() {
30+
return Err(Error::InvalidUri);
31+
}
32+
let storage_type = &uri[..idx];
2933

30-
match part {
34+
match storage_type {
3135
"mem" => {
3236
#[cfg(feature = "storage-mem")]
3337
{
34-
Ok(Box::new(super::mem::MemStorage::new()))
38+
Ok(Box::new(super::mem::MemStorage::new(loc)))
3539
}
3640
#[cfg(not(feature = "storage-mem"))]
3741
{
@@ -41,7 +45,7 @@ fn parse_uri(uri: &str) -> Result<Box<dyn Storable>> {
4145
"file" => {
4246
#[cfg(feature = "storage-file")]
4347
{
44-
let path = std::path::Path::new(&uri[idx + 3..]);
48+
let path = std::path::Path::new(loc);
4549
let depot = super::file::FileStorage::new(path);
4650
Ok(Box::new(depot))
4751
}
@@ -53,7 +57,7 @@ fn parse_uri(uri: &str) -> Result<Box<dyn Storable>> {
5357
"sqlite" => {
5458
#[cfg(feature = "storage-sqlite")]
5559
{
56-
let depot = super::sqlite::SqliteStorage::new(&uri[idx + 3..]);
60+
let depot = super::sqlite::SqliteStorage::new(loc);
5761
Ok(Box::new(depot))
5862
}
5963
#[cfg(not(feature = "storage-sqlite"))]
@@ -64,7 +68,7 @@ fn parse_uri(uri: &str) -> Result<Box<dyn Storable>> {
6468
"redis" => {
6569
#[cfg(feature = "storage-redis")]
6670
{
67-
let depot = super::redis::RedisStorage::new(&uri[idx + 3..])?;
71+
let depot = super::redis::RedisStorage::new(loc)?;
6872
Ok(Box::new(depot))
6973
}
7074
#[cfg(not(feature = "storage-redis"))]
@@ -75,7 +79,7 @@ fn parse_uri(uri: &str) -> Result<Box<dyn Storable>> {
7579
"faulty" => {
7680
#[cfg(feature = "storage-faulty")]
7781
{
78-
let depot = super::faulty::FaultyStorage::new(&uri[idx + 3..]);
82+
let depot = super::faulty::FaultyStorage::new(loc);
7983
Ok(Box::new(depot))
8084
}
8185
#[cfg(not(feature = "storage-faulty"))]
@@ -86,7 +90,7 @@ fn parse_uri(uri: &str) -> Result<Box<dyn Storable>> {
8690
"zbox" => {
8791
#[cfg(feature = "storage-zbox")]
8892
{
89-
let depot = super::zbox::ZboxStorage::new(&uri[idx + 3..])?;
93+
let depot = super::zbox::ZboxStorage::new(loc)?;
9094
Ok(Box::new(depot))
9195
}
9296
#[cfg(not(feature = "storage-zbox"))]

0 commit comments

Comments
 (0)