Skip to content

Commit 50e1522

Browse files
committed
🐛 fix(ios/fs): Make sure that &str names dont exceed MAX_PATH_LENGTH (64)
1 parent ca54a0c commit 50e1522

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/ios/fs.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ where
180180
{
181181
let filesystem = ios::open(c"/dev/fs", Mode::ReadWrite)?;
182182

183+
if directory_path.len() > 64 {
184+
return Err(ios::Error::Invalid);
185+
}
186+
183187
let mut path = [0u8; 64];
184188
let path_len = directory_path.len();
185189
path[0..path_len].copy_from_slice(directory_path.as_bytes());
@@ -234,6 +238,10 @@ pub fn set_attributes(attributes: Attributes) -> Result<(), ios::Error> {
234238
pub fn get_attributes(name: &str) -> Result<Attributes, ios::Error> {
235239
let filesystem = ios::open(c"/dev/fs", Mode::ReadWrite)?;
236240

241+
if name.len() > 64 {
242+
return Err(ios::Error::Invalid);
243+
}
244+
237245
let mut in_buf = [0u8; 64];
238246
in_buf[0..name.len()].copy_from_slice(name.as_bytes());
239247

@@ -259,6 +267,10 @@ pub fn get_attributes(name: &str) -> Result<Attributes, ios::Error> {
259267
pub fn delete(name: &str) -> Result<(), ios::Error> {
260268
let filesystem = ios::open(c"/dev/fs", Mode::ReadWrite)?;
261269

270+
if name.len() > 64 {
271+
return Err(ios::Error::Invalid);
272+
}
273+
262274
let mut in_buf = [0u8; 64];
263275
in_buf[0..name.len()].copy_from_slice(name.as_bytes());
264276

@@ -275,6 +287,13 @@ pub fn delete(name: &str) -> Result<(), ios::Error> {
275287
pub fn rename(source_name: &str, destination_name: &str) -> Result<(), ios::Error> {
276288
let filesystem = ios::open(c"/dev/fs", Mode::ReadWrite)?;
277289

290+
if source_name.len() > 64 {
291+
return Err(ios::Error::Invalid);
292+
}
293+
if destination_name.len() > 64 {
294+
return Err(ios::Error::Invalid);
295+
}
296+
278297
let mut in_buf = [0u8; 128];
279298
in_buf[0..source_name.len()].copy_from_slice(source_name.as_bytes());
280299
in_buf[64..64 + destination_name.len()].copy_from_slice(destination_name.as_bytes());
@@ -319,6 +338,10 @@ pub struct FileStats {
319338
pub fn read_file_stats(file_name: &str) -> Result<FileStats, ios::Error> {
320339
let filesystem = ios::open(c"/dev/fs", Mode::ReadWrite)?;
321340

341+
if file_name.len() > 64 {
342+
return Err(ios::Error::Invalid);
343+
}
344+
322345
let mut file_buf = [0u8; 64];
323346
file_buf[0..file_name.len()].copy_from_slice(file_name.as_bytes());
324347
let file_name = CStr::from_bytes_with_nul(&file_buf[0..=file_name.len()])
@@ -353,6 +376,10 @@ pub struct Usage {
353376
pub fn get_usage(name: &str) -> Result<Usage, ios::Error> {
354377
let filesystem = ios::open(c"/dev/fs", Mode::ReadWrite)?;
355378

379+
if name.len() > 64 {
380+
return Err(ios::Error::Invalid);
381+
}
382+
356383
let mut in_buf = [0u8; 64];
357384
in_buf[0..name.len()].copy_from_slice(name.as_bytes());
358385

0 commit comments

Comments
 (0)