Skip to content

Commit

Permalink
Merge branch 'for-linus' of git://oss.sgi.com:8090/xfs/xfs-2.6
Browse files Browse the repository at this point in the history
* 'for-linus' of git://oss.sgi.com:8090/xfs/xfs-2.6:
  [XFS] fix unaligned access in readdir
  • Loading branch information
Linus Torvalds committed Jan 11, 2008
2 parents 5d0381e + aea6ad0 commit 460c54b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions fs/xfs/linux-2.6/xfs_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ xfs_file_readdir(
#else

struct hack_dirent {
int namlen;
loff_t offset;
u64 ino;
loff_t offset;
int namlen;
unsigned int d_type;
char name[];
};
Expand All @@ -285,16 +285,18 @@ xfs_hack_filldir(
{
struct hack_callback *buf = __buf;
struct hack_dirent *de = (struct hack_dirent *)(buf->dirent + buf->used);
unsigned int reclen;

if (buf->used + sizeof(struct hack_dirent) + namlen > buf->len)
reclen = ALIGN(sizeof(struct hack_dirent) + namlen, sizeof(u64));
if (buf->used + reclen > buf->len)
return -EINVAL;

de->namlen = namlen;
de->offset = offset;
de->ino = ino;
de->d_type = d_type;
memcpy(de->name, name, namlen);
buf->used += sizeof(struct hack_dirent) + namlen;
buf->used += reclen;
return 0;
}

Expand Down Expand Up @@ -334,7 +336,8 @@ xfs_file_readdir(
offset = filp->f_pos;

while (!eof) {
int reclen;
unsigned int reclen;

start_offset = offset;

buf.used = 0;
Expand All @@ -355,7 +358,8 @@ xfs_file_readdir(
goto done;
}

reclen = sizeof(struct hack_dirent) + de->namlen;
reclen = ALIGN(sizeof(struct hack_dirent) + de->namlen,
sizeof(u64));
size -= reclen;
de = (struct hack_dirent *)((char *)de + reclen);
curr_offset = de->offset /* & 0x7fffffff */;
Expand Down

0 comments on commit 460c54b

Please sign in to comment.