[PATCH 1/4] Move check for invalid chars to vfat_valid_longname()

From: lsr
Date: Mon Nov 08 2004 - 20:42:50 EST


This patch moves the check for invalid characters into
vfat_valid_longname(), i.e. before the filename is converted to Unicode.
Benefits: It's simpler to check the non-Unicode string and now all
checks are done in one place. Note: we don't need to check for / (slash)
as this is already done by VFS.

--- ./fs/vfat/namei.c.orig 2004-11-08 18:35:52.000000000 +0100
+++ ./fs/vfat/namei.c 2004-11-08 18:37:06.000000000 +0100
@@ -24,6 +24,7 @@
#include <linux/smp_lock.h>
#include <linux/buffer_head.h>
#include <linux/namei.h>
+#include <linux/string.h>

static int vfat_hashi(struct dentry *parent, struct qstr *qstr);
static int vfat_hash(struct dentry *parent, struct qstr *qstr);
@@ -158,14 +159,6 @@ static int vfat_cmp(struct dentry *dentr

/* Characters that are undesirable in an MS-DOS file name */

-static wchar_t bad_chars[] = {
- /* `*' `?' `<' `>' `|' `"' `:' `/' */
- 0x002A, 0x003F, 0x003C, 0x003E, 0x007C, 0x0022, 0x003A, 0x002F,
- /* `\' */
- 0x005C, 0,
-};
-#define IS_BADCHAR(uni) (vfat_unistrchr(bad_chars, (uni)) != NULL)
-
static wchar_t replace_chars[] = {
/* `[' `]' `;' `,' `+' `=' */
0x005B, 0x005D, 0x003B, 0x002C, 0x002B, 0x003D, 0,
@@ -187,18 +180,10 @@ static inline wchar_t *vfat_unistrchr(co
return (wchar_t *) s;
}

-static inline int vfat_is_used_badchars(const wchar_t *s, int len)
-{
- int i;
-
- for (i = 0; i < len; i++)
- if (s[i] < 0x0020 || IS_BADCHAR(s[i]))
- return -EINVAL;
- return 0;
-}
-
static int vfat_valid_longname(const unsigned char *name, unsigned int len)
{
+ const unsigned char *p;
+
if (len && name[len-1] == ' ')
return 0;
if (len >= 256)
@@ -221,6 +206,12 @@ static int vfat_valid_longname(const uns
}
}

+ /* check for invalid characters */
+ for (p = name; p < name + len; p++) {
+ if (*p < 0x0020 || strchr("*?<>|\":\\", *p) != NULL)
+ return 0;
+ }
+
return 1;
}

@@ -636,10 +627,6 @@ static int vfat_build_slots(struct inode
if (res < 0)
goto out_free;

- res = vfat_is_used_badchars(uname, ulen);
- if (res < 0)
- goto out_free;
-
res = vfat_create_shortname(dir, sbi->nls_disk, uname, ulen,
msdos_name, &lcase);
if (res < 0)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/