FreeCalypso > hg > freecalypso-sw
changeset 232:73372cfdaf7f
tiffs IVA: object name validation implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 26 Jan 2014 08:42:59 +0000 |
parents | 5ceacdbd4490 |
children | ae9ff2d1e3da |
files | ffstools/tiffs-rd/basics.c ffstools/tiffs-rd/inode.c |
diffstat | 2 files changed, 52 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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 <string.h> #include <strings.h> #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); + } }
--- 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 <sys/types.h> #include <endian.h> +#include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -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); +}