Commit 066b9cde authored by Jan Kara's avatar Jan Kara

udf: Use separate buffer for copying split names

Code in udf_find_entry() and udf_readdir() used the same buffer for
storing filename that was split among blocks and for the resulting
filename in utf8. This worked because udf_get_filename() first
internally copied the name into a different buffer and only then
performed a conversion into the destination buffer. However we want to
get rid of intermediate buffers so use separate buffer for converted
name and name split between blocks so that we don't have the same source
and destination buffer when converting split names.
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent 9fba7056
...@@ -45,7 +45,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx) ...@@ -45,7 +45,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
int block, iblock; int block, iblock;
loff_t nf_pos; loff_t nf_pos;
int flen; int flen;
unsigned char *fname = NULL; unsigned char *fname = NULL, *copy_name = NULL;
unsigned char *nameptr; unsigned char *nameptr;
uint16_t liu; uint16_t liu;
uint8_t lfi; uint8_t lfi;
...@@ -143,7 +143,15 @@ static int udf_readdir(struct file *file, struct dir_context *ctx) ...@@ -143,7 +143,15 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
if (poffset >= lfi) { if (poffset >= lfi) {
nameptr = (char *)(fibh.ebh->b_data + poffset - lfi); nameptr = (char *)(fibh.ebh->b_data + poffset - lfi);
} else { } else {
nameptr = fname; if (!copy_name) {
copy_name = kmalloc(UDF_NAME_LEN,
GFP_NOFS);
if (!copy_name) {
ret = -ENOMEM;
goto out;
}
}
nameptr = copy_name;
memcpy(nameptr, fi->fileIdent + liu, memcpy(nameptr, fi->fileIdent + liu,
lfi - poffset); lfi - poffset);
memcpy(nameptr + lfi - poffset, memcpy(nameptr + lfi - poffset,
...@@ -185,6 +193,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx) ...@@ -185,6 +193,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
brelse(fibh.sbh); brelse(fibh.sbh);
brelse(epos.bh); brelse(epos.bh);
kfree(fname); kfree(fname);
kfree(copy_name);
return ret; return ret;
} }
......
...@@ -165,7 +165,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir, ...@@ -165,7 +165,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
struct fileIdentDesc *fi = NULL; struct fileIdentDesc *fi = NULL;
loff_t f_pos; loff_t f_pos;
int block, flen; int block, flen;
unsigned char *fname = NULL; unsigned char *fname = NULL, *copy_name = NULL;
unsigned char *nameptr; unsigned char *nameptr;
uint8_t lfi; uint8_t lfi;
uint16_t liu; uint16_t liu;
...@@ -236,7 +236,15 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir, ...@@ -236,7 +236,15 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
nameptr = (uint8_t *)(fibh->ebh->b_data + nameptr = (uint8_t *)(fibh->ebh->b_data +
poffset - lfi); poffset - lfi);
else { else {
nameptr = fname; if (!copy_name) {
copy_name = kmalloc(UDF_NAME_LEN,
GFP_NOFS);
if (!copy_name) {
fi = ERR_PTR(-ENOMEM);
goto out_err;
}
}
nameptr = copy_name;
memcpy(nameptr, fi->fileIdent + liu, memcpy(nameptr, fi->fileIdent + liu,
lfi - poffset); lfi - poffset);
memcpy(nameptr + lfi - poffset, memcpy(nameptr + lfi - poffset,
...@@ -279,6 +287,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir, ...@@ -279,6 +287,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
out_ok: out_ok:
brelse(epos.bh); brelse(epos.bh);
kfree(fname); kfree(fname);
kfree(copy_name);
return fi; return fi;
} }
......
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