diff options
author | Wang Sheng-Hui <shhuiw@gmail.com> | 2011-07-22 09:50:13 -0400 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2011-07-22 13:41:16 -0400 |
commit | 03b5bb342978f99f75fb36d69cd29bab32109fd4 (patch) | |
tree | 495099b74e217de7c322a1bf4737901a1efb8a3a /fs/ext2 | |
parent | c878c73f8dda48f64bcec24f78e80e154cbc5cf8 (diff) |
ext2: check xattr name_len before acquiring xattr_sem in ext2_xattr_get
In ext2_xattr_get(), the code will acquire xattr_sem first, later checks
the length of xattr name_len > 255. It's unnecessarily time consuming and
also ext2_xattr_set() checks the length before other checks. So move the
check before acquiring xattr_sem to make these two functions consistent.
Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/ext2')
-rw-r--r-- | fs/ext2/xattr.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c index 529970617a21..d27b71f1d183 100644 --- a/fs/ext2/xattr.c +++ b/fs/ext2/xattr.c | |||
@@ -161,6 +161,10 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name, | |||
161 | 161 | ||
162 | if (name == NULL) | 162 | if (name == NULL) |
163 | return -EINVAL; | 163 | return -EINVAL; |
164 | name_len = strlen(name); | ||
165 | if (name_len > 255) | ||
166 | return -ERANGE; | ||
167 | |||
164 | down_read(&EXT2_I(inode)->xattr_sem); | 168 | down_read(&EXT2_I(inode)->xattr_sem); |
165 | error = -ENODATA; | 169 | error = -ENODATA; |
166 | if (!EXT2_I(inode)->i_file_acl) | 170 | if (!EXT2_I(inode)->i_file_acl) |
@@ -181,12 +185,8 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_get", | |||
181 | error = -EIO; | 185 | error = -EIO; |
182 | goto cleanup; | 186 | goto cleanup; |
183 | } | 187 | } |
184 | /* find named attribute */ | ||
185 | name_len = strlen(name); | ||
186 | 188 | ||
187 | error = -ERANGE; | 189 | /* find named attribute */ |
188 | if (name_len > 255) | ||
189 | goto cleanup; | ||
190 | entry = FIRST_ENTRY(bh); | 190 | entry = FIRST_ENTRY(bh); |
191 | while (!IS_LAST_ENTRY(entry)) { | 191 | while (!IS_LAST_ENTRY(entry)) { |
192 | struct ext2_xattr_entry *next = | 192 | struct ext2_xattr_entry *next = |