Skip to content

Commit 5ceb8b5

Browse files
Fabian Frederickjankara
authored andcommitted
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: Fabian Frederick <fabf@skynet.be> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent c0655fe commit 5ceb8b5

4 files changed

Lines changed: 12 additions & 7 deletions

File tree

‎fs/udf/dir.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
168168
}
169169

170170
flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN);
171-
if (!flen)
171+
if (flen <= 0)
172172
continue;
173173

174174
tloc = lelb_to_cpu(cfi.icb.extLocation);

‎fs/udf/namei.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
234234
continue;
235235

236236
flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN);
237-
if (flen && udf_match(flen, fname, child->len, child->name))
237+
if (flen > 0 && udf_match(flen, fname, child->len, child->name))
238238
goto out_ok;
239239
}
240240

‎fs/udf/symlink.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ static int udf_pc_to_char(struct super_block *sb, unsigned char *from,
8282
comp_len = udf_get_filename(sb, pc->componentIdent,
8383
pc->lengthComponentIdent,
8484
p, tolen);
85+
if (comp_len < 0)
86+
return comp_len;
87+
8588
p += comp_len;
8689
tolen -= comp_len;
8790
if (tolen == 0)

‎fs/udf/unicode.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,17 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen,
338338
uint8_t *dname, int dlen)
339339
{
340340
struct ustr *filename, *unifilename;
341-
int len = 0;
341+
int ret = 0;
342342

343343
filename = kmalloc(sizeof(struct ustr), GFP_NOFS);
344344
if (!filename)
345-
return 0;
345+
return -ENOMEM;
346346

347347
unifilename = kmalloc(sizeof(struct ustr), GFP_NOFS);
348-
if (!unifilename)
348+
if (!unifilename) {
349+
ret = -ENOMEM;
349350
goto out1;
351+
}
350352

351353
if (udf_build_ustr_exact(unifilename, sname, slen))
352354
goto out2;
@@ -367,14 +369,14 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen,
367369
} else
368370
goto out2;
369371

370-
len = udf_translate_to_linux(dname, dlen,
372+
ret = udf_translate_to_linux(dname, dlen,
371373
filename->u_name, filename->u_len,
372374
unifilename->u_name, unifilename->u_len);
373375
out2:
374376
kfree(unifilename);
375377
out1:
376378
kfree(filename);
377-
return len;
379+
return ret;
378380
}
379381

380382
int udf_put_filename(struct super_block *sb, const uint8_t *sname,

0 commit comments

Comments
 (0)