1
1
//! Objects related to [`FilesystemStore`] live here.
2
2
use lightning:: util:: persist:: KVStore ;
3
+ use lightning:: util:: string:: PrintableString ;
3
4
4
5
use std:: collections:: HashMap ;
5
6
use std:: fs;
@@ -53,7 +54,17 @@ impl KVStore for FilesystemStore {
53
54
54
55
fn read ( & self , namespace : & str , key : & str ) -> std:: io:: Result < Self :: Reader > {
55
56
if key. is_empty ( ) {
56
- let msg = format ! ( "Failed to read {}/{}: key may not be empty." , namespace, key) ;
57
+ let msg = format ! ( "Failed to read {}/{}: key may not be empty." ,
58
+ PrintableString ( namespace) , PrintableString ( key) ) ;
59
+ return Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , msg) ) ;
60
+ }
61
+
62
+ if namespace. chars ( ) . any ( |c| !c. is_ascii ( ) || c. is_control ( ) ) ||
63
+ key. chars ( ) . any ( |c| !c. is_ascii ( ) || c. is_control ( ) ) {
64
+ debug_assert ! ( false , "Failed to read {}/{}: namespace and key must be valid ASCII
65
+ strings." , PrintableString ( namespace) , PrintableString ( key) ) ;
66
+ let msg = format ! ( "Failed to read {}/{}: namespace and key must be valid ASCII strings." ,
67
+ PrintableString ( namespace) , PrintableString ( key) ) ;
57
68
return Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , msg) ) ;
58
69
}
59
70
@@ -69,7 +80,17 @@ impl KVStore for FilesystemStore {
69
80
70
81
fn write ( & self , namespace : & str , key : & str , buf : & [ u8 ] ) -> std:: io:: Result < ( ) > {
71
82
if key. is_empty ( ) {
72
- let msg = format ! ( "Failed to write {}/{}: key may not be empty." , namespace, key) ;
83
+ let msg = format ! ( "Failed to write {}/{}: key may not be empty." ,
84
+ PrintableString ( namespace) , PrintableString ( key) ) ;
85
+ return Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , msg) ) ;
86
+ }
87
+
88
+ if namespace. chars ( ) . any ( |c| !c. is_ascii ( ) || c. is_control ( ) ) ||
89
+ key. chars ( ) . any ( |c| !c. is_ascii ( ) || c. is_control ( ) ) {
90
+ debug_assert ! ( false , "Failed to write {}/{}: namespace and key must be valid ASCII
91
+ strings." , PrintableString ( namespace) , PrintableString ( key) ) ;
92
+ let msg = format ! ( "Failed to write {}/{}: namespace and key must be valid ASCII strings." ,
93
+ PrintableString ( namespace) , PrintableString ( key) ) ;
73
94
return Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , msg) ) ;
74
95
}
75
96
@@ -144,7 +165,17 @@ impl KVStore for FilesystemStore {
144
165
145
166
fn remove ( & self , namespace : & str , key : & str ) -> std:: io:: Result < ( ) > {
146
167
if key. is_empty ( ) {
147
- let msg = format ! ( "Failed to remove {}/{}: key may not be empty." , namespace, key) ;
168
+ let msg = format ! ( "Failed to remove {}/{}: key may not be empty." ,
169
+ PrintableString ( namespace) , PrintableString ( key) ) ;
170
+ return Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , msg) ) ;
171
+ }
172
+
173
+ if namespace. chars ( ) . any ( |c| !c. is_ascii ( ) || c. is_control ( ) ) ||
174
+ key. chars ( ) . any ( |c| !c. is_ascii ( ) || c. is_control ( ) ) {
175
+ debug_assert ! ( false , "Failed to remove {}/{}: namespace and key must be valid ASCII
176
+ strings." , PrintableString ( namespace) , PrintableString ( key) ) ;
177
+ let msg = format ! ( "Failed to remove {}/{}: namespace and key must be valid ASCII strings." ,
178
+ PrintableString ( namespace) , PrintableString ( key) ) ;
148
179
return Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , msg) ) ;
149
180
}
150
181
0 commit comments