Skip to content

Commit 1ad8583

Browse files
committed
add more file folder name check
1 parent 256bc9c commit 1ad8583

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

fw/application/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,10 +613,10 @@ CFLAGS += -DBOARD_$(BOARD)
613613
ifneq ($(RELEASE), 1)
614614
CFLAGS += -DDEBUG
615615
CFLAGS += -DEBUG_NRF
616-
# CFLAGS += -DU8G2_USE_LARGE_GB2312_FONT
616+
#CFLAGS += -DU8G2_USE_LARGE_FONTS
617617
else
618618
CFLAGS += -DNDEBUG
619-
CFLAGS += -DU8G2_USE_LARGE_GB2312_FONT
619+
CFLAGS += -DU8G2_USE_LARGE_FONTS
620620
endif
621621
CFLAGS += -DMBEDTLS_CONFIG_FILE=\"nrf_crypto_mbedtls_config.h\"
622622
CFLAGS += -DM_USE_THREAD_BACKEND=0

fw/application/src/mod/vfs/vfs_driver_spiffs.c

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,28 @@ static s32_t vfs_spiffs_map_error_code(s32_t err) {
4949
return VFS_ERR_FAIL;
5050
}
5151

52-
static int32_t vfs_check_file_path(const char* file_path){
53-
if(strlen(file_path) >= VFS_MAX_PATH_LEN){
52+
static int32_t vfs_check_file_path(const char *file_path) {
53+
if (strlen(file_path) >= VFS_MAX_PATH_LEN) {
5454
return VFS_ERR_MAXNM;
5555
}
56-
const char* basename;
56+
const char *basename;
5757
size_t length;
5858
cwk_path_get_basename(file_path, &basename, &length);
59-
if(length <= 0 || length >= VFS_MAX_NAME_LEN){
59+
if (length <= 0 || length >= VFS_MAX_NAME_LEN) {
60+
return VFS_ERR_MAXNM;
61+
}
62+
return VFS_OK;
63+
}
64+
65+
static int32_t vfs_check_folder_path(const char *file_path) {
66+
int32_t ret = vfs_check_file_path(file_path);
67+
if (ret != VFS_OK) {
68+
return ret;
69+
}
70+
if (strlen(file_path) + strlen(VFS_SPIFFS_FOLDER_NAME) + 1 >= VFS_MAX_PATH_LEN) {
6071
return VFS_ERR_MAXNM;
6172
}
73+
6274
return VFS_OK;
6375
}
6476

@@ -160,6 +172,11 @@ int32_t vfs_spiffs_stat_file(const char *file, vfs_obj_t *obj) {
160172
char path[SPIFFS_OBJ_NAME_LEN];
161173
memset(obj, 0, sizeof(vfs_obj_t));
162174

175+
int res = vfs_check_file_path(file);
176+
if (res != VFS_OK) {
177+
return res;
178+
}
179+
163180
if (SPIFFS_stat(&fs, file, &s) == SPIFFS_OK) {
164181
cwk_path_get_basename(s.name, &basename, &length);
165182

@@ -289,12 +306,15 @@ int32_t vfs_spiffs_close_dir(vfs_dir_t *fd) {
289306
int32_t vfs_spiffs_create_dir(const char *dir) {
290307
char path[VFS_MAX_PATH_LEN];
291308

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){
309+
NRF_LOG_INFO("create dir %s, %d\n", nrf_log_push(dir), strlen(dir));
310+
int res = vfs_check_folder_path(dir);
311+
if (res != VFS_OK) {
312+
NRF_LOG_INFO("folder path check failed: %d", res);
295313
return res;
296314
}
315+
297316
snprintf(path, sizeof(path), "%s/%s", dir, VFS_SPIFFS_FOLDER_NAME);
317+
298318
res = SPIFFS_creat(&fs, path, 0);
299319
return vfs_spiffs_map_error_code(res);
300320
}
@@ -335,13 +355,13 @@ int32_t vfs_spiffs_rename_dir_internal(const char *dir_name, const char *new_dir
335355
vfs_spiffs_dir_t *p_dir = &dir;
336356
int32_t err_code = VFS_OK;
337357

338-
int ret = vfs_check_file_path(dir_name);
339-
if( ret != VFS_OK){
358+
int ret = vfs_check_folder_path(dir_name);
359+
if (ret != VFS_OK) {
340360
return ret;
341361
}
342362

343-
int ret2 = vfs_check_file_path(new_dir_name);
344-
if( ret2 != VFS_OK){
363+
int ret2 = vfs_check_folder_path(new_dir_name);
364+
if (ret2 != VFS_OK) {
345365
return ret;
346366
}
347367

@@ -396,7 +416,7 @@ int32_t vfs_spiffs_rename_dir(const char *dir_name, const char *new_dir_name) {
396416
/**file operations*/
397417
int32_t vfs_spiffs_open_file(const char *file, vfs_file_t *fd, uint32_t flags) {
398418
int ret = vfs_check_file_path(file);
399-
if( ret != VFS_OK){
419+
if (ret != VFS_OK) {
400420
return ret;
401421
}
402422
fd->handle = SPIFFS_open(&fs, file, flags, 0);
@@ -464,7 +484,7 @@ int32_t vfs_spiffs_write_file_data(const char *file, void *buff, size_t buff_siz
464484
NRF_LOG_INFO("write file data %s\n", nrf_log_push(file));
465485

466486
int ret = vfs_check_file_path(file);
467-
if( ret != VFS_OK){
487+
if (ret != VFS_OK) {
468488
return ret;
469489
}
470490

@@ -499,10 +519,16 @@ int32_t vfs_spiffs_read_file_data(const char *file, void *buff, size_t buff_size
499519
}
500520

501521
int32_t vfs_spiffs_rename_file(const char *file, const char *new_file) {
502-
if (strlen(new_file) >= SPIFFS_OBJ_NAME_LEN) {
503-
NRF_LOG_INFO("rename file error, file %s new file %s is too long");
504-
return VFS_ERR_MAXNM;
522+
int32_t ret = vfs_check_file_path(file);
523+
if (ret != VFS_OK) {
524+
return ret;
505525
}
526+
527+
ret = vfs_check_file_path(new_file);
528+
if (ret != VFS_OK) {
529+
return ret;
530+
}
531+
506532
NRF_LOG_INFO("rename file %s => %s\n", nrf_log_push(file), nrf_log_push(new_file));
507533
int res = SPIFFS_rename(&fs, file, new_file);
508534
return vfs_spiffs_map_error_code(res);

fw/application/src/mui/u8g2_font_wqy12_t_gb2312a_lite.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Glyphs: 983/30503
1111
BBX Build Mode: 0
1212
*/
13-
#ifndef U8G2_USE_LARGE_GB2312_FONT
13+
#ifndef U8G2_USE_LARGE_FONTS
1414
const uint8_t u8g2_font_wqy12_t_gb2312a[24116] U8G2_FONT_SECTION("u8g2_font_wqy12_t_gb2312a") =
1515
"\327\0\3\2\4\4\4\4\5\14\15\0\376\10\376\12\377\1d\2\332\5n \5\0\230\26!\7\221\212"
1616
"\26\247\0\42\7\64\371\26\221)#\16\226\210\67Q\313\260D\275\14K\324\2$\17\245xV\331RQ"

0 commit comments

Comments
 (0)