Ticket #1491: dosfs-2.patch

File dosfs-2.patch, 2.1 KB (added by Chris Johns, on 03/05/10 at 03:41:35)

DOS file name eval fix

  • libfs/src/dosfs/msdos_misc.c

    RCS file: /usr1/CVS/rtems/cpukit/libfs/src/dosfs/msdos_misc.c,v
    retrieving revision 1.19
    diff -p -u -r1.19 msdos_misc.c
    msdos_short_name_hex(char* sfn, int num) 
    110110static msdos_name_type_t
    111111msdos_name_type(const char *name, int name_len)
    112112{
    113     bool dot = false;
    114113    bool lowercase = false;
    115114    bool uppercase = false;
    116     int  dot_at = 0;
     115    int  dot_at = -1;
    117116    int  count = 0;
    118117
    119118    while (*name && (count < name_len))
    120119    {
     120        bool is_dot = *name == '.';
    121121        msdos_name_type_t type = msdos_is_valid_name_char(*name);
    122122
    123123        if ((type == MSDOS_NAME_INVALID) || (type == MSDOS_NAME_LONG))
    124124            return type;
    125125
    126         if (dot)
     126        if (dot_at >= 0)
    127127        {
    128             if ((*name == '.') || ((count - dot_at) > 3))
     128            if (is_dot || ((count - dot_at) > 3))
    129129                return MSDOS_NAME_LONG;
    130130        }
    131131        else
    132132        {
    133             if (count >= 8)
     133            if (count == 8 && !is_dot)
    134134                return MSDOS_NAME_LONG;
    135135        }
    136136
    137         if (*name == '.')
    138         {
    139             dot = true;
     137        if (is_dot)
    140138            dot_at = count;
    141         }
    142139        else if ((*name >= 'A') && (*name <= 'Z'))
    143140            uppercase = true;
    144141        else if ((*name >= 'a') && (*name <= 'z'))
    msdos_long_to_short(const char *lfn, int 
    194191     * Filenames with only blanks and dots are not allowed!
    195192     */
    196193    for (i = 0; i < lfn_len; i++)
    197         if ((lfn[i] != ' ') && (lfn[i] == '.'))
     194        if ((lfn[i] != ' ') && (lfn[i] != '.'))
    198195            break;
    199196
    200     if (i > lfn_len)
     197    if (i == lfn_len)
    201198        return MSDOS_NAME_INVALID;
    202199
    203200    /*
    msdos_get_token(const char *path, 
    238235    *ret_token = NULL;
    239236    *ret_token_len = 0;
    240237
     238    if (pathlen == 0)
     239        return MSDOS_NO_MORE_PATH;
     240   
    241241    /*
    242242     *  Check for a separator.
    243243     */