Skip to content

Commit 339844a

Browse files
committed
Merge branch 'hotfix.1' into next
Signed-off-by: Sayan Nandan <nandansayan@outlook.com>
2 parents 6a10f92 + 38b0112 commit 339844a

File tree

8 files changed

+215
-102
lines changed

8 files changed

+215
-102
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
data.bin
44
/server/snapshots
55
snapstore.bin
6-
snapstore.partmap
6+
snapstore.partmap
7+
/snapshots

.idea/workspace.xml

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.lock

Lines changed: 22 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/admin/mksnap.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::resp::GroupBegin;
3434
use libsky::terrapipe::RespCodes;
3535
use libsky::TResult;
3636
use std::hint::unreachable_unchecked;
37-
use std::path::PathBuf;
37+
use std::path::{Component, PathBuf};
3838

3939
/// Create a snapshot
4040
///
@@ -121,6 +121,25 @@ pub async fn mksnap(handle: &CoreDB, con: &mut Con<'_>, act: ActionGroup) -> TRe
121121
let mut path = PathBuf::from(DIR_SNAPSHOT);
122122
path.push("remote");
123123
path.push(snapname.to_owned() + ".snapshot");
124+
let illegal_snapshot = path
125+
.components()
126+
.filter(|dir| {
127+
// Sanitize snapshot name, to avoid directory traversal attacks
128+
// If the snapshot name has any root directory or parent directory, then
129+
// we'll allow it to pass through this adaptor.
130+
// As a result, this iterator will give us a count of the 'bad' components
131+
dir == &Component::RootDir || dir == &Component::ParentDir
132+
})
133+
.count()
134+
!= 0;
135+
if illegal_snapshot {
136+
con.write_response(GroupBegin(1)).await?;
137+
return con
138+
.write_response(RespCodes::OtherError(Some(
139+
"err-invalid-snapshot-name".to_owned(),
140+
)))
141+
.await;
142+
}
124143
let failed;
125144
{
126145
match diskstore::flush_data(&path, &handle.acquire_read().get_ref()) {
@@ -146,4 +165,4 @@ pub async fn mksnap(handle: &CoreDB, con: &mut Con<'_>, act: ActionGroup) -> TRe
146165
.await;
147166
}
148167
}
149-
}
168+
}

server/src/cli.yml

Lines changed: 76 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3,81 +3,79 @@ version: 0.5.1
33
author: Sayan N. <ohsayan@outlook.com>
44
about: The Skybase Database server
55
args:
6-
- config:
7-
short: c
8-
required: false
9-
long: withconfig
10-
value_name: cfgfile
11-
help: Sets a configuration file to start sdb
12-
takes_value: true
13-
- restore:
14-
short: r
15-
required: false
16-
long: restore
17-
value_name: snapshotfile
18-
help: Restores data from a previous snapshot
19-
takes_value: true
20-
- host:
21-
short: h
22-
required: false
23-
long: host
24-
value_name: host
25-
help: Sets the host to which the server will bind
26-
takes_value: true
27-
- port:
28-
short: p
29-
required: false
30-
long: port
31-
value_name: port
32-
help: Sets the port to which the server will bind
33-
takes_value: true
34-
- noart:
35-
required: false
36-
long: noart
37-
help: Disables terminal artwork
38-
takes_value: false
39-
- nosave:
40-
required: false
41-
long: nosave
42-
help: Disables automated background saving
43-
takes_value: false
44-
- saveduration:
45-
required: false
46-
long: saveduration
47-
value_name: duration
48-
short: S
49-
takes_value: true
50-
help: Set the BGSAVE duration
51-
- snapevery:
52-
required: false
53-
long: snapevery
54-
value_name: duration
55-
help: Set the periodic snapshot duration
56-
takes_value: true
57-
- snapkeep:
58-
required: false
59-
long: snapkeep
60-
value_name: count
61-
help: Sets the number of most recent snapshots to keep
62-
takes_value: true
63-
- sslkey:
64-
required: false
65-
long: sslkey
66-
short: k
67-
value_name: key
68-
help: Sets the PEM key file to use for SSL/TLS
69-
takes_value: true
70-
- sslchain:
71-
required: false
72-
long: sslchain
73-
short: z
74-
value_name: chain
75-
help: Sets the PEM chain file to use for SSL/TLS
76-
takes_value: true
77-
- sslonly:
78-
required: false
79-
long: sslonly
80-
takes_value: false
81-
help: >-
82-
Tells the server to only accept SSL connections and disables the non-SSL
83-
port
6+
- config:
7+
short: c
8+
required: false
9+
long: withconfig
10+
value_name: cfgfile
11+
help: Sets a configuration file to start sdb
12+
takes_value: true
13+
- restore:
14+
short: r
15+
required: false
16+
long: restore
17+
value_name: snapshotfile
18+
help: Restores data from a previous snapshot
19+
takes_value: true
20+
- host:
21+
short: h
22+
required: false
23+
long: host
24+
value_name: host
25+
help: Sets the host to which the server will bind
26+
takes_value: true
27+
- port:
28+
short: p
29+
required: false
30+
long: port
31+
value_name: port
32+
help: Sets the port to which the server will bind
33+
takes_value: true
34+
- noart:
35+
required: false
36+
long: noart
37+
help: Disables terminal artwork
38+
takes_value: false
39+
- nosave:
40+
required: false
41+
long: nosave
42+
help: Disables automated background saving
43+
takes_value: false
44+
- saveduration:
45+
required: false
46+
long: saveduration
47+
value_name: duration
48+
short: S
49+
takes_value: true
50+
help: Set the BGSAVE duration
51+
- snapevery:
52+
required: false
53+
long: snapevery
54+
value_name: duration
55+
help: Set the periodic snapshot duration
56+
takes_value: true
57+
- snapkeep:
58+
required: false
59+
long: snapkeep
60+
value_name: count
61+
help: Sets the number of most recent snapshots to keep
62+
takes_value: true
63+
- sslkey:
64+
required: false
65+
long: sslkey
66+
short: k
67+
value_name: key
68+
help: Sets the PEM key file to use for SSL/TLS
69+
takes_value: true
70+
- sslchain:
71+
required: false
72+
long: sslchain
73+
short: z
74+
value_name: chain
75+
help: Sets the PEM chain file to use for SSL/TLS
76+
takes_value: true
77+
- sslonly:
78+
required: false
79+
long: sslonly
80+
takes_value: false
81+
help: Tells the server to only accept SSL connections and disables the non-SSL port

0 commit comments

Comments
 (0)