aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/fat/namei_vfat.c83
1 files changed, 36 insertions, 47 deletions
diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index a81eb2367d3..aae3b4e1057 100644
--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -521,57 +521,46 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
521 521
522 op = &outname[*outlen * sizeof(wchar_t)]; 522 op = &outname[*outlen * sizeof(wchar_t)];
523 } else { 523 } else {
524 if (nls) { 524 for (i = 0, ip = name, op = outname, *outlen = 0;
525 for (i = 0, ip = name, op = outname, *outlen = 0; 525 i < len && *outlen <= FAT_LFN_LEN;
526 i < len && *outlen <= FAT_LFN_LEN; 526 *outlen += 1) {
527 *outlen += 1) 527 if (escape && (*ip == ':')) {
528 { 528 if (i > len - 5)
529 if (escape && (*ip == ':')) { 529 return -EINVAL;
530 if (i > len - 5) 530 ec = 0;
531 return -EINVAL; 531 for (k = 1; k < 5; k++) {
532 ec = 0; 532 nc = ip[k];
533 for (k = 1; k < 5; k++) { 533 ec <<= 4;
534 nc = ip[k]; 534 if (nc >= '0' && nc <= '9') {
535 ec <<= 4; 535 ec |= nc - '0';
536 if (nc >= '0' && nc <= '9') { 536 continue;
537 ec |= nc - '0';
538 continue;
539 }
540 if (nc >= 'a' && nc <= 'f') {
541 ec |= nc - ('a' - 10);
542 continue;
543 }
544 if (nc >= 'A' && nc <= 'F') {
545 ec |= nc - ('A' - 10);
546 continue;
547 }
548 return -EINVAL;
549 } 537 }
550 *op++ = ec & 0xFF; 538 if (nc >= 'a' && nc <= 'f') {
551 *op++ = ec >> 8; 539 ec |= nc - ('a' - 10);
552 ip += 5; 540 continue;
553 i += 5; 541 }
554 } else { 542 if (nc >= 'A' && nc <= 'F') {
555 if ((charlen = nls->char2uni(ip, len - i, (wchar_t *)op)) < 0) 543 ec |= nc - ('A' - 10);
556 return -EINVAL; 544 continue;
557 ip += charlen; 545 }
558 i += charlen; 546 return -EINVAL;
559 op += 2;
560 } 547 }
548 *op++ = ec & 0xFF;
549 *op++ = ec >> 8;
550 ip += 5;
551 i += 5;
552 } else {
553 charlen = nls->char2uni(ip, len - i,
554 (wchar_t *)op);
555 if (charlen < 0)
556 return -EINVAL;
557 ip += charlen;
558 i += charlen;
559 op += 2;
561 } 560 }
562 if (i < len)
563 return -ENAMETOOLONG;
564 } else {
565 for (i = 0, ip = name, op = outname, *outlen = 0;
566 i < len && *outlen <= FAT_LFN_LEN;
567 i++, *outlen += 1)
568 {
569 *op++ = *ip++;
570 *op++ = 0;
571 }
572 if (i < len)
573 return -ENAMETOOLONG;
574 } 561 }
562 if (i < len)
563 return -ENAMETOOLONG;
575 } 564 }
576 565
577 *longlen = *outlen; 566 *longlen = *outlen;