Commit 5ceb8b55 authored by Fabian Frederick's avatar Fabian Frederick Committed by Jan Kara

udf: Return -ENOMEM when allocation fails in udf_get_filename()

Return -ENOMEM when allocation fails in udf_get_filename(). Update
udf_pc_to_char(), udf_readdir(), and udf_find_entry() to handle the
error appropriately. This allows us to pass appropriate error to
userspace instead of corrupting symlink contents by omitting some path
elements.
Signed-off-by: default avatarFabian Frederick <fabf@skynet.be>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent c0655fe9
...@@ -168,7 +168,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx) ...@@ -168,7 +168,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
} }
flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN); flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN);
if (!flen) if (flen <= 0)
continue; continue;
tloc = lelb_to_cpu(cfi.icb.extLocation); tloc = lelb_to_cpu(cfi.icb.extLocation);
......
...@@ -234,7 +234,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir, ...@@ -234,7 +234,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
continue; continue;
flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN); flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN);
if (flen && udf_match(flen, fname, child->len, child->name)) if (flen > 0 && udf_match(flen, fname, child->len, child->name))
goto out_ok; goto out_ok;
} }
......
...@@ -82,6 +82,9 @@ static int udf_pc_to_char(struct super_block *sb, unsigned char *from, ...@@ -82,6 +82,9 @@ static int udf_pc_to_char(struct super_block *sb, unsigned char *from,
comp_len = udf_get_filename(sb, pc->componentIdent, comp_len = udf_get_filename(sb, pc->componentIdent,
pc->lengthComponentIdent, pc->lengthComponentIdent,
p, tolen); p, tolen);
if (comp_len < 0)
return comp_len;
p += comp_len; p += comp_len;
tolen -= comp_len; tolen -= comp_len;
if (tolen == 0) if (tolen == 0)
......
...@@ -338,15 +338,17 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen, ...@@ -338,15 +338,17 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen,
uint8_t *dname, int dlen) uint8_t *dname, int dlen)
{ {
struct ustr *filename, *unifilename; struct ustr *filename, *unifilename;
int len = 0; int ret = 0;
filename = kmalloc(sizeof(struct ustr), GFP_NOFS); filename = kmalloc(sizeof(struct ustr), GFP_NOFS);
if (!filename) if (!filename)
return 0; return -ENOMEM;
unifilename = kmalloc(sizeof(struct ustr), GFP_NOFS); unifilename = kmalloc(sizeof(struct ustr), GFP_NOFS);
if (!unifilename) if (!unifilename) {
ret = -ENOMEM;
goto out1; goto out1;
}
if (udf_build_ustr_exact(unifilename, sname, slen)) if (udf_build_ustr_exact(unifilename, sname, slen))
goto out2; goto out2;
...@@ -367,14 +369,14 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen, ...@@ -367,14 +369,14 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen,
} else } else
goto out2; goto out2;
len = udf_translate_to_linux(dname, dlen, ret = udf_translate_to_linux(dname, dlen,
filename->u_name, filename->u_len, filename->u_name, filename->u_len,
unifilename->u_name, unifilename->u_len); unifilename->u_name, unifilename->u_len);
out2: out2:
kfree(unifilename); kfree(unifilename);
out1: out1:
kfree(filename); kfree(filename);
return len; return ret;
} }
int udf_put_filename(struct super_block *sb, const uint8_t *sname, int udf_put_filename(struct super_block *sb, const uint8_t *sname,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment