# HG changeset patch # User Michael Spacefalcon # Date 1390725779 0 # Node ID 73372cfdaf7f0dd9dfbd4bdd1742762f556384ff # Parent 5ceacdbd44903085abe244443de7d39b3eff2e68 tiffs IVA: object name validation implemented diff -r 5ceacdbd4490 -r 73372cfdaf7f ffstools/tiffs-rd/basics.c --- a/ffstools/tiffs-rd/basics.c Sun Jan 26 08:11:42 2014 +0000 +++ b/ffstools/tiffs-rd/basics.c Sun Jan 26 08:42:59 2014 +0000 @@ -12,6 +12,7 @@ #include #include #include "types.h" +#include "struct.h" #include "globals.h" u8 tiffs_header[6] = {'F', 'f', 's', '#', 0x10, 0x02}; @@ -136,5 +137,12 @@ alloc_inode_table(); find_root_inode(); printf("Root inode is #%x\n", root_inode); - exit(0); + if (validate_obj_name(root_inode, 1)) { + printf("Root inode (format) name: %s\n", + inode_info[root_inode]->dataptr); + exit(0); + } else { + printf("No valid name found in the root inode!\n"); + exit(1); + } } diff -r 5ceacdbd4490 -r 73372cfdaf7f ffstools/tiffs-rd/inode.c --- a/ffstools/tiffs-rd/inode.c Sun Jan 26 08:11:42 2014 +0000 +++ b/ffstools/tiffs-rd/inode.c Sun Jan 26 08:42:59 2014 +0000 @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -11,6 +12,7 @@ #include "types.h" #include "struct.h" #include "globals.h" +#include "pathname.h" u8 blank_flash_line[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; @@ -159,3 +161,44 @@ fprintf(stderr, "error: no root inode found; try -r\n"); exit(1); } + +validate_obj_name(ino, root_special) +{ + struct inode_info *inf = inode_info[ino]; + u8 *p, *endp; + int c; + + if (!inf->len) + return(0); + p = inf->dataptr; + endp = p + inf->len; + for (; ; p++) { + if (p >= endp) + return(0); + c = *p; + if (!c) + break; + if (c < ' ' || c > '~') + return(0); + if (root_special || isalnum(c)) + continue; + switch (c) { + case '.': + case ',': + case '_': + case '-': + case '+': + case '%': + case '$': + case '#': + continue; + default: + return(0); + } + } + c = p - inf->dataptr; + if (c < 1 || c > MAX_FN_COMPONENT && !root_special) + return(0); + inf->byte_after_name = p + 1; + return(1); +}