Skip to content

Commit

Permalink
udf: fix i_nlink limit
Browse files Browse the repository at this point in the history
(256 << sizeof(x)) - 1 is not the maximal possible value of x...
In reality, the maximal allowed value for UDF FileLinkCount is
65535.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Al Viro committed Mar 3, 2011
1 parent 99890a3 commit 810c1b2
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions fs/udf/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <linux/crc-itu-t.h>
#include <linux/exportfs.h>

enum { UDF_MAX_LINKS = 0xffff };

static inline int udf_match(int len1, const unsigned char *name1, int len2,
const unsigned char *name2)
{
Expand Down Expand Up @@ -650,7 +652,7 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
struct udf_inode_info *iinfo;

err = -EMLINK;
if (dir->i_nlink >= (256 << sizeof(dir->i_nlink)) - 1)
if (dir->i_nlink >= UDF_MAX_LINKS)
goto out;

err = -EIO;
Expand Down Expand Up @@ -1034,9 +1036,8 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir,
struct fileIdentDesc cfi, *fi;
int err;

if (inode->i_nlink >= (256 << sizeof(inode->i_nlink)) - 1) {
if (inode->i_nlink >= UDF_MAX_LINKS)
return -EMLINK;
}

fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
if (!fi) {
Expand Down Expand Up @@ -1131,9 +1132,7 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
goto end_rename;

retval = -EMLINK;
if (!new_inode &&
new_dir->i_nlink >=
(256 << sizeof(new_dir->i_nlink)) - 1)
if (!new_inode && new_dir->i_nlink >= UDF_MAX_LINKS)
goto end_rename;
}
if (!nfi) {
Expand Down

0 comments on commit 810c1b2

Please sign in to comment.