@@ -49,6 +49,19 @@ static s32_t vfs_spiffs_map_error_code(s32_t err) {
49
49
return VFS_ERR_FAIL ;
50
50
}
51
51
52
+ static int32_t vfs_check_file_path (const char * file_path ){
53
+ if (strlen (file_path ) >= VFS_MAX_PATH_LEN ){
54
+ return VFS_ERR_MAXNM ;
55
+ }
56
+ const char * basename ;
57
+ size_t length ;
58
+ cwk_path_get_basename (file_path , & basename , & length );
59
+ if (length <= 0 || length >= VFS_MAX_NAME_LEN ){
60
+ return VFS_ERR_MAXNM ;
61
+ }
62
+ return VFS_OK ;
63
+ }
64
+
52
65
static s32_t spiffs_block_read (u32_t addr , u32_t size , u8_t * dst ) { return hal_spi_flash_read (addr , dst , size ); }
53
66
54
67
static s32_t spiffs_block_write (u32_t addr , u32_t size , u8_t * src ) { return hal_spi_flash_prog (addr , src , size ); }
@@ -277,8 +290,12 @@ int32_t vfs_spiffs_create_dir(const char *dir) {
277
290
char path [VFS_MAX_PATH_LEN ];
278
291
279
292
NRF_LOG_INFO ("create dir %s\n" , nrf_log_push (dir ));
293
+ int res = vfs_check_file_path (dir );
294
+ if (res != VFS_OK ){
295
+ return res ;
296
+ }
280
297
snprintf (path , sizeof (path ), "%s/%s" , dir , VFS_SPIFFS_FOLDER_NAME );
281
- int res = SPIFFS_creat (& fs , path , 0 );
298
+ res = SPIFFS_creat (& fs , path , 0 );
282
299
return vfs_spiffs_map_error_code (res );
283
300
}
284
301
@@ -318,6 +335,16 @@ int32_t vfs_spiffs_rename_dir_internal(const char *dir_name, const char *new_dir
318
335
vfs_spiffs_dir_t * p_dir = & dir ;
319
336
int32_t err_code = VFS_OK ;
320
337
338
+ int ret = vfs_check_file_path (dir_name );
339
+ if ( ret != VFS_OK ){
340
+ return ret ;
341
+ }
342
+
343
+ int ret2 = vfs_check_file_path (new_dir_name );
344
+ if ( ret2 != VFS_OK ){
345
+ return ret ;
346
+ }
347
+
321
348
p_dir -> pe = & p_dir -> e ;
322
349
cwalk_dir_prefix_match (p_dir -> dir , dir_name );
323
350
@@ -368,6 +395,10 @@ int32_t vfs_spiffs_rename_dir(const char *dir_name, const char *new_dir_name) {
368
395
369
396
/**file operations*/
370
397
int32_t vfs_spiffs_open_file (const char * file , vfs_file_t * fd , uint32_t flags ) {
398
+ int ret = vfs_check_file_path (file );
399
+ if ( ret != VFS_OK ){
400
+ return ret ;
401
+ }
371
402
fd -> handle = SPIFFS_open (& fs , file , flags , 0 );
372
403
if (fd -> handle < 0 ) {
373
404
return vfs_spiffs_map_error_code (fd -> handle );
@@ -431,6 +462,12 @@ int32_t vfs_spiffs_update_file_meta(const char *file, void *meta, size_t meta_si
431
462
int32_t vfs_spiffs_write_file_data (const char * file , void * buff , size_t buff_size ) {
432
463
433
464
NRF_LOG_INFO ("write file data %s\n" , nrf_log_push (file ));
465
+
466
+ int ret = vfs_check_file_path (file );
467
+ if ( ret != VFS_OK ){
468
+ return ret ;
469
+ }
470
+
434
471
spiffs_file fd = SPIFFS_open (& fs , file , SPIFFS_WRONLY | SPIFFS_CREAT | SPIFFS_TRUNC , 0 );
435
472
if (fd < 0 ) {
436
473
return vfs_spiffs_map_error_code (fd );
0 commit comments