Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Mine
Tuesday, July 3rd, 2007 at 9:13:44am UTC 

  1. Index: firmware/drivers/fat.c
  2. ===================================================================
  3. --- firmware/drivers/fat.c      (revision 13767)
  4. +++ firmware/drivers/fat.c      (working copy)
  5. @@ -1172,13 +1172,47 @@
  6.      
  7.      return 0;
  8.  }
  9. -
  10. +static bool is_char_legal(char c)
  11. +{
  12. +    switch(c)
  13. +    {
  14. +        case 0x22: /* " */
  15. +        case 0x2a: /* * */
  16. +        case 0x2b: /* + */
  17. +        case 0x2c: /* , */
  18. +        case 0x2e: /* . */
  19. +        case 0x3a: /* : */
  20. +        case 0x3b: /* ; */
  21. +        case 0x3c: /* < */
  22. +        case 0x3d: /* = */
  23. +        case 0x3e: /* > */
  24. +        case 0x3f: /* ? */
  25. +        case 0x5b: /* [ */
  26. +        case 0x5c: /* \ */
  27. +        case 0x5d: /* ] */
  28. +        case 0x7c: /* | */
  29. +            return false;
  30. +        default:
  31. +            if(c < 0x20) /* space */
  32. +                return false;
  33. +    }
  34. +    return true;
  35. +}
  36.  static int fat_checkname(const unsigned char* newname)
  37.  {
  38. +    int len = strlen(newname);
  39.      /* More sanity checks are probably needed */
  40. -    if ( newname[strlen(newname) - 1] == '.' ) {
  41. +    if (len > 255 || newname[len - 1] == '.' ||
  42. +        newname[0] == ' ' || newname[len - 1] == ' ' )
  43. +    {
  44.          return -1;
  45.      }
  46. +    while (*newname)
  47. +    {
  48. +        if (!is_char_legal(*newname))
  49. +            return -1;
  50. +        newname++;
  51. +    }
  52.      return 0;
  53.  }
  54.  
  55. @@ -1346,35 +1380,19 @@
  56.  
  57.  static unsigned char char2dos(unsigned char c, int* randomize)
  58.  {
  59. -    switch(c)
  60. +    if (!is_char_legal(c))
  61.      {
  62. -        case 0x22:
  63. -        case 0x2a:
  64. -        case 0x2b:
  65. -        case 0x2c:
  66. -        case 0x2e:
  67. -        case 0x3a:
  68. -        case 0x3b:
  69. -        case 0x3c:
  70. -        case 0x3d:
  71. -        case 0x3e:
  72. -        case 0x3f:
  73. -        case 0x5b:
  74. -        case 0x5c:
  75. -        case 0x5d:
  76. -        case 0x7c:
  77. +        if(c <= 0x20)
  78. +            c = 0;   /* Illegal char, remove */
  79. +        else
  80. +        {
  81.              /* Illegal char, replace */
  82.              c = '_';
  83.              *randomize = 1; /* as per FAT spec */
  84. -            break;
  85. -               
  86. -        default:
  87. -            if(c <= 0x20)
  88. -                c = 0;   /* Illegal char, remove */
  89. -            else
  90. -                c = toupper(c);
  91. -            break;
  92. +        }
  93.      }
  94. +    else
  95. +        c = toupper(c);
  96.      return c;
  97.  }
  98.  

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right worth-right