Generated v2 prefixes
This commit is contained in:
+67
-49
@@ -3,16 +3,17 @@
|
||||
|
||||
# invalid pointer tests (outside of block_count)
|
||||
|
||||
[[case]] # invalid tail-pointer test
|
||||
define.TAIL_TYPE = ['LFS2_TYPE_HARDTAIL', 'LFS2_TYPE_SOFTTAIL']
|
||||
define.INVALSET = [0x3, 0x1, 0x2]
|
||||
[cases.test_evil_invalid_tail_pointer]
|
||||
defines.TAIL_TYPE = ['LFS2_TYPE_HARDTAIL', 'LFS2_TYPE_SOFTTAIL']
|
||||
defines.INVALSET = [0x3, 0x1, 0x2]
|
||||
in = "lfs2.c"
|
||||
code = '''
|
||||
// create littlefs
|
||||
lfs2_format(&lfs2, &cfg) => 0;
|
||||
lfs2_t lfs2;
|
||||
lfs2_format(&lfs2, cfg) => 0;
|
||||
|
||||
// change tail-pointer to invalid pointers
|
||||
lfs2_init(&lfs2, &cfg) => 0;
|
||||
lfs2_init(&lfs2, cfg) => 0;
|
||||
lfs2_mdir_t mdir;
|
||||
lfs2_dir_fetch(&lfs2, &mdir, (lfs2_block_t[2]){0, 1}) => 0;
|
||||
lfs2_dir_commit(&lfs2, &mdir, LFS2_MKATTRS(
|
||||
@@ -23,25 +24,27 @@ code = '''
|
||||
lfs2_deinit(&lfs2) => 0;
|
||||
|
||||
// test that mount fails gracefully
|
||||
lfs2_mount(&lfs2, &cfg) => LFS2_ERR_CORRUPT;
|
||||
lfs2_mount(&lfs2, cfg) => LFS2_ERR_CORRUPT;
|
||||
'''
|
||||
|
||||
[[case]] # invalid dir pointer test
|
||||
define.INVALSET = [0x3, 0x1, 0x2]
|
||||
[cases.test_evil_invalid_dir_pointer]
|
||||
defines.INVALSET = [0x3, 0x1, 0x2]
|
||||
in = "lfs2.c"
|
||||
code = '''
|
||||
// create littlefs
|
||||
lfs2_format(&lfs2, &cfg) => 0;
|
||||
lfs2_t lfs2;
|
||||
lfs2_format(&lfs2, cfg) => 0;
|
||||
// make a dir
|
||||
lfs2_mount(&lfs2, &cfg) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
lfs2_mkdir(&lfs2, "dir_here") => 0;
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
|
||||
// change the dir pointer to be invalid
|
||||
lfs2_init(&lfs2, &cfg) => 0;
|
||||
lfs2_init(&lfs2, cfg) => 0;
|
||||
lfs2_mdir_t mdir;
|
||||
lfs2_dir_fetch(&lfs2, &mdir, (lfs2_block_t[2]){0, 1}) => 0;
|
||||
// make sure id 1 == our directory
|
||||
uint8_t buffer[1024];
|
||||
lfs2_dir_get(&lfs2, &mdir,
|
||||
LFS2_MKTAG(0x700, 0x3ff, 0),
|
||||
LFS2_MKTAG(LFS2_TYPE_NAME, 1, strlen("dir_here")), buffer)
|
||||
@@ -57,14 +60,17 @@ code = '''
|
||||
|
||||
// test that accessing our bad dir fails, note there's a number
|
||||
// of ways to access the dir, some can fail, but some don't
|
||||
lfs2_mount(&lfs2, &cfg) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
struct lfs2_info info;
|
||||
lfs2_stat(&lfs2, "dir_here", &info) => 0;
|
||||
assert(strcmp(info.name, "dir_here") == 0);
|
||||
assert(info.type == LFS2_TYPE_DIR);
|
||||
|
||||
lfs2_dir_t dir;
|
||||
lfs2_dir_open(&lfs2, &dir, "dir_here") => LFS2_ERR_CORRUPT;
|
||||
lfs2_stat(&lfs2, "dir_here/file_here", &info) => LFS2_ERR_CORRUPT;
|
||||
lfs2_dir_open(&lfs2, &dir, "dir_here/dir_here") => LFS2_ERR_CORRUPT;
|
||||
lfs2_file_t file;
|
||||
lfs2_file_open(&lfs2, &file, "dir_here/file_here",
|
||||
LFS2_O_RDONLY) => LFS2_ERR_CORRUPT;
|
||||
lfs2_file_open(&lfs2, &file, "dir_here/file_here",
|
||||
@@ -72,24 +78,27 @@ code = '''
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # invalid file pointer test
|
||||
[cases.test_evil_invalid_file_pointer]
|
||||
in = "lfs2.c"
|
||||
define.SIZE = [10, 1000, 100000] # faked file size
|
||||
defines.SIZE = [10, 1000, 100000] # faked file size
|
||||
code = '''
|
||||
// create littlefs
|
||||
lfs2_format(&lfs2, &cfg) => 0;
|
||||
lfs2_t lfs2;
|
||||
lfs2_format(&lfs2, cfg) => 0;
|
||||
// make a file
|
||||
lfs2_mount(&lfs2, &cfg) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
lfs2_file_t file;
|
||||
lfs2_file_open(&lfs2, &file, "file_here",
|
||||
LFS2_O_WRONLY | LFS2_O_CREAT) => 0;
|
||||
lfs2_file_close(&lfs2, &file) => 0;
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
|
||||
// change the file pointer to be invalid
|
||||
lfs2_init(&lfs2, &cfg) => 0;
|
||||
lfs2_init(&lfs2, cfg) => 0;
|
||||
lfs2_mdir_t mdir;
|
||||
lfs2_dir_fetch(&lfs2, &mdir, (lfs2_block_t[2]){0, 1}) => 0;
|
||||
// make sure id 1 == our file
|
||||
uint8_t buffer[1024];
|
||||
lfs2_dir_get(&lfs2, &mdir,
|
||||
LFS2_MKTAG(0x700, 0x3ff, 0),
|
||||
LFS2_MKTAG(LFS2_TYPE_NAME, 1, strlen("file_here")), buffer)
|
||||
@@ -103,7 +112,8 @@ code = '''
|
||||
|
||||
// test that accessing our bad file fails, note there's a number
|
||||
// of ways to access the dir, some can fail, but some don't
|
||||
lfs2_mount(&lfs2, &cfg) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
struct lfs2_info info;
|
||||
lfs2_stat(&lfs2, "file_here", &info) => 0;
|
||||
assert(strcmp(info.name, "file_here") == 0);
|
||||
assert(info.type == LFS2_TYPE_REG);
|
||||
@@ -114,20 +124,22 @@ code = '''
|
||||
lfs2_file_close(&lfs2, &file) => 0;
|
||||
|
||||
// any allocs that traverse CTZ must unfortunately must fail
|
||||
if (SIZE > 2*LFS2_BLOCK_SIZE) {
|
||||
if (SIZE > 2*BLOCK_SIZE) {
|
||||
lfs2_mkdir(&lfs2, "dir_here") => LFS2_ERR_CORRUPT;
|
||||
}
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # invalid pointer in CTZ skip-list test
|
||||
define.SIZE = ['2*LFS2_BLOCK_SIZE', '3*LFS2_BLOCK_SIZE', '4*LFS2_BLOCK_SIZE']
|
||||
[cases.test_evil_invalid_ctz_pointer] # invalid pointer in CTZ skip-list test
|
||||
defines.SIZE = ['2*BLOCK_SIZE', '3*BLOCK_SIZE', '4*BLOCK_SIZE']
|
||||
in = "lfs2.c"
|
||||
code = '''
|
||||
// create littlefs
|
||||
lfs2_format(&lfs2, &cfg) => 0;
|
||||
lfs2_t lfs2;
|
||||
lfs2_format(&lfs2, cfg) => 0;
|
||||
// make a file
|
||||
lfs2_mount(&lfs2, &cfg) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
lfs2_file_t file;
|
||||
lfs2_file_open(&lfs2, &file, "file_here",
|
||||
LFS2_O_WRONLY | LFS2_O_CREAT) => 0;
|
||||
for (int i = 0; i < SIZE; i++) {
|
||||
@@ -137,10 +149,11 @@ code = '''
|
||||
lfs2_file_close(&lfs2, &file) => 0;
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
// change pointer in CTZ skip-list to be invalid
|
||||
lfs2_init(&lfs2, &cfg) => 0;
|
||||
lfs2_init(&lfs2, cfg) => 0;
|
||||
lfs2_mdir_t mdir;
|
||||
lfs2_dir_fetch(&lfs2, &mdir, (lfs2_block_t[2]){0, 1}) => 0;
|
||||
// make sure id 1 == our file and get our CTZ structure
|
||||
uint8_t buffer[4*BLOCK_SIZE];
|
||||
lfs2_dir_get(&lfs2, &mdir,
|
||||
LFS2_MKTAG(0x700, 0x3ff, 0),
|
||||
LFS2_MKTAG(LFS2_TYPE_NAME, 1, strlen("file_here")), buffer)
|
||||
@@ -153,18 +166,19 @@ code = '''
|
||||
=> LFS2_MKTAG(LFS2_TYPE_CTZSTRUCT, 1, sizeof(struct lfs2_ctz));
|
||||
lfs2_ctz_fromle32(&ctz);
|
||||
// rewrite block to contain bad pointer
|
||||
uint8_t bbuffer[LFS2_BLOCK_SIZE];
|
||||
cfg.read(&cfg, ctz.head, 0, bbuffer, LFS2_BLOCK_SIZE) => 0;
|
||||
uint8_t bbuffer[BLOCK_SIZE];
|
||||
cfg->read(cfg, ctz.head, 0, bbuffer, BLOCK_SIZE) => 0;
|
||||
uint32_t bad = lfs2_tole32(0xcccccccc);
|
||||
memcpy(&bbuffer[0], &bad, sizeof(bad));
|
||||
memcpy(&bbuffer[4], &bad, sizeof(bad));
|
||||
cfg.erase(&cfg, ctz.head) => 0;
|
||||
cfg.prog(&cfg, ctz.head, 0, bbuffer, LFS2_BLOCK_SIZE) => 0;
|
||||
cfg->erase(cfg, ctz.head) => 0;
|
||||
cfg->prog(cfg, ctz.head, 0, bbuffer, BLOCK_SIZE) => 0;
|
||||
lfs2_deinit(&lfs2) => 0;
|
||||
|
||||
// test that accessing our bad file fails, note there's a number
|
||||
// of ways to access the dir, some can fail, but some don't
|
||||
lfs2_mount(&lfs2, &cfg) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
struct lfs2_info info;
|
||||
lfs2_stat(&lfs2, "file_here", &info) => 0;
|
||||
assert(strcmp(info.name, "file_here") == 0);
|
||||
assert(info.type == LFS2_TYPE_REG);
|
||||
@@ -175,22 +189,23 @@ code = '''
|
||||
lfs2_file_close(&lfs2, &file) => 0;
|
||||
|
||||
// any allocs that traverse CTZ must unfortunately must fail
|
||||
if (SIZE > 2*LFS2_BLOCK_SIZE) {
|
||||
if (SIZE > 2*BLOCK_SIZE) {
|
||||
lfs2_mkdir(&lfs2, "dir_here") => LFS2_ERR_CORRUPT;
|
||||
}
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
'''
|
||||
|
||||
|
||||
[[case]] # invalid gstate pointer
|
||||
define.INVALSET = [0x3, 0x1, 0x2]
|
||||
[cases.test_evil_invalid_gstate_pointer]
|
||||
defines.INVALSET = [0x3, 0x1, 0x2]
|
||||
in = "lfs2.c"
|
||||
code = '''
|
||||
// create littlefs
|
||||
lfs2_format(&lfs2, &cfg) => 0;
|
||||
lfs2_t lfs2;
|
||||
lfs2_format(&lfs2, cfg) => 0;
|
||||
|
||||
// create an invalid gstate
|
||||
lfs2_init(&lfs2, &cfg) => 0;
|
||||
lfs2_init(&lfs2, cfg) => 0;
|
||||
lfs2_mdir_t mdir;
|
||||
lfs2_dir_fetch(&lfs2, &mdir, (lfs2_block_t[2]){0, 1}) => 0;
|
||||
lfs2_fs_prepmove(&lfs2, 1, (lfs2_block_t [2]){
|
||||
@@ -202,21 +217,22 @@ code = '''
|
||||
// test that mount fails gracefully
|
||||
// mount may not fail, but our first alloc should fail when
|
||||
// we try to fix the gstate
|
||||
lfs2_mount(&lfs2, &cfg) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
lfs2_mkdir(&lfs2, "should_fail") => LFS2_ERR_CORRUPT;
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
'''
|
||||
|
||||
# cycle detection/recovery tests
|
||||
|
||||
[[case]] # metadata-pair threaded-list loop test
|
||||
[cases.test_evil_mdir_loop] # metadata-pair threaded-list loop test
|
||||
in = "lfs2.c"
|
||||
code = '''
|
||||
// create littlefs
|
||||
lfs2_format(&lfs2, &cfg) => 0;
|
||||
lfs2_t lfs2;
|
||||
lfs2_format(&lfs2, cfg) => 0;
|
||||
|
||||
// change tail-pointer to point to ourself
|
||||
lfs2_init(&lfs2, &cfg) => 0;
|
||||
lfs2_init(&lfs2, cfg) => 0;
|
||||
lfs2_mdir_t mdir;
|
||||
lfs2_dir_fetch(&lfs2, &mdir, (lfs2_block_t[2]){0, 1}) => 0;
|
||||
lfs2_dir_commit(&lfs2, &mdir, LFS2_MKATTRS(
|
||||
@@ -225,20 +241,21 @@ code = '''
|
||||
lfs2_deinit(&lfs2) => 0;
|
||||
|
||||
// test that mount fails gracefully
|
||||
lfs2_mount(&lfs2, &cfg) => LFS2_ERR_CORRUPT;
|
||||
lfs2_mount(&lfs2, cfg) => LFS2_ERR_CORRUPT;
|
||||
'''
|
||||
|
||||
[[case]] # metadata-pair threaded-list 2-length loop test
|
||||
[cases.test_evil_mdir_loop2] # metadata-pair threaded-list 2-length loop test
|
||||
in = "lfs2.c"
|
||||
code = '''
|
||||
// create littlefs with child dir
|
||||
lfs2_format(&lfs2, &cfg) => 0;
|
||||
lfs2_mount(&lfs2, &cfg) => 0;
|
||||
lfs2_t lfs2;
|
||||
lfs2_format(&lfs2, cfg) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
lfs2_mkdir(&lfs2, "child") => 0;
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
|
||||
// find child
|
||||
lfs2_init(&lfs2, &cfg) => 0;
|
||||
lfs2_init(&lfs2, cfg) => 0;
|
||||
lfs2_mdir_t mdir;
|
||||
lfs2_block_t pair[2];
|
||||
lfs2_dir_fetch(&lfs2, &mdir, (lfs2_block_t[2]){0, 1}) => 0;
|
||||
@@ -255,20 +272,21 @@ code = '''
|
||||
lfs2_deinit(&lfs2) => 0;
|
||||
|
||||
// test that mount fails gracefully
|
||||
lfs2_mount(&lfs2, &cfg) => LFS2_ERR_CORRUPT;
|
||||
lfs2_mount(&lfs2, cfg) => LFS2_ERR_CORRUPT;
|
||||
'''
|
||||
|
||||
[[case]] # metadata-pair threaded-list 1-length child loop test
|
||||
[cases.test_evil_mdir_loop_child] # metadata-pair threaded-list 1-length child loop test
|
||||
in = "lfs2.c"
|
||||
code = '''
|
||||
// create littlefs with child dir
|
||||
lfs2_format(&lfs2, &cfg) => 0;
|
||||
lfs2_mount(&lfs2, &cfg) => 0;
|
||||
lfs2_t lfs2;
|
||||
lfs2_format(&lfs2, cfg) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
lfs2_mkdir(&lfs2, "child") => 0;
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
|
||||
// find child
|
||||
lfs2_init(&lfs2, &cfg) => 0;
|
||||
lfs2_init(&lfs2, cfg) => 0;
|
||||
lfs2_mdir_t mdir;
|
||||
lfs2_block_t pair[2];
|
||||
lfs2_dir_fetch(&lfs2, &mdir, (lfs2_block_t[2]){0, 1}) => 0;
|
||||
@@ -284,5 +302,5 @@ code = '''
|
||||
lfs2_deinit(&lfs2) => 0;
|
||||
|
||||
// test that mount fails gracefully
|
||||
lfs2_mount(&lfs2, &cfg) => LFS2_ERR_CORRUPT;
|
||||
lfs2_mount(&lfs2, cfg) => LFS2_ERR_CORRUPT;
|
||||
'''
|
||||
|
||||
Reference in New Issue
Block a user