Skip to content

Commit

Permalink
befs: Validate length of long symbolic links.
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Warns <warns@pre-sense.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Timo Warns authored and torvalds committed Aug 17, 2011
1 parent b4fd4ae commit 338d0f0
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions fs/befs/linuxvfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,17 +474,22 @@ befs_follow_link(struct dentry *dentry, struct nameidata *nd)
befs_data_stream *data = &befs_ino->i_data.ds;
befs_off_t len = data->size;

befs_debug(sb, "Follow long symlink");

link = kmalloc(len, GFP_NOFS);
if (!link) {
link = ERR_PTR(-ENOMEM);
} else if (befs_read_lsymlink(sb, data, link, len) != len) {
kfree(link);
befs_error(sb, "Failed to read entire long symlink");
if (len == 0) {
befs_error(sb, "Long symlink with illegal length");
link = ERR_PTR(-EIO);
} else {
link[len - 1] = '\0';
befs_debug(sb, "Follow long symlink");

link = kmalloc(len, GFP_NOFS);
if (!link) {
link = ERR_PTR(-ENOMEM);
} else if (befs_read_lsymlink(sb, data, link, len) != len) {
kfree(link);
befs_error(sb, "Failed to read entire long symlink");
link = ERR_PTR(-EIO);
} else {
link[len - 1] = '\0';
}
}
} else {
link = befs_ino->i_data.symlink;
Expand Down

0 comments on commit 338d0f0

Please sign in to comment.