comparison rvinterf/etmsync/fsread.c @ 921:74d284add54d

fc-fsio: guard against bogus readdir results from the target If the FFS being operated on contains SE K2x0 extended filenames, readdir will return strings that are bad for printing. We need to guard against this possibility, and also against possible other bogosity that could be sent by other alien firmwares.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 31 Dec 2022 22:55:23 +0000
parents d332fbf5c145
children
comparison
equal deleted inserted replaced
920:0306449ba467 921:74d284add54d
48 default: 48 default:
49 printf("?%c %s\n", readonly, pathname); 49 printf("?%c %s\n", readonly, pathname);
50 } 50 }
51 } 51 }
52 52
53 ls_is_sane(name)
54 char *name;
55 {
56 char *cp;
57 int c;
58
59 cp = name;
60 while (c = *cp++) {
61 if (c < '!' || c > '~')
62 return(0);
63 }
64 return(1);
65 }
66
53 do_ls_long(lsarg) 67 do_ls_long(lsarg)
54 char *lsarg; 68 char *lsarg;
55 { 69 {
56 struct stat_info stat; 70 struct stat_info stat;
57 u_char rdstate[4]; 71 u_char rdstate[4];
83 rc = do_readdir(rdstate, rdbuf, MAX_FN_COMPONENT+1); 97 rc = do_readdir(rdstate, rdbuf, MAX_FN_COMPONENT+1);
84 if (rc) 98 if (rc)
85 return(rc); 99 return(rc);
86 if (index(rdbuf, '/')) { 100 if (index(rdbuf, '/')) {
87 printf("error: readdir result contains a slash\n"); 101 printf("error: readdir result contains a slash\n");
102 return(ERROR_TARGET);
103 }
104 if (!ls_is_sane(rdbuf)) {
105 printf("error: readdir result contains non-printable chars\n");
88 return(ERROR_TARGET); 106 return(ERROR_TARGET);
89 } 107 }
90 strcpy(childp, rdbuf); 108 strcpy(childp, rdbuf);
91 rc = do_xlstat(childpath, &stat); 109 rc = do_xlstat(childpath, &stat);
92 if (rc) { 110 if (rc) {
233 return(rc); 251 return(rc);
234 if (index(rdbuf, '/')) { 252 if (index(rdbuf, '/')) {
235 printf("error: readdir result contains a slash\n"); 253 printf("error: readdir result contains a slash\n");
236 return(ERROR_TARGET); 254 return(ERROR_TARGET);
237 } 255 }
256 if (!ls_is_sane(rdbuf)) {
257 printf("error: readdir result contains non-printable chars\n");
258 return(ERROR_TARGET);
259 }
238 strcpy(childp, rdbuf); 260 strcpy(childp, rdbuf);
239 if (rdbuf[0] == '.') { 261 if (rdbuf[0] == '.') {
240 printf("skipping %s\n", ffspath_child); 262 printf("skipping %s\n", ffspath_child);
241 continue; 263 continue;
242 } 264 }