Skip to content

Commit 9fba705

Browse files
agabbasovjankara
authored andcommitted
udf: Adjust UDF_NAME_LEN to better reflect actual restrictions
Actual name length restriction is 254 bytes, this is used in 'ustr' structure, and this is what fits into UDF File Ident structures. And in most cases the constant is used as UDF_NAME_LEN-2. So, it's better to just modify the constant to make it closer to reality. Also, in some cases it's useful to have a separate constant for the maximum length of file name field in CS0 encoding in UDF File Ident structures. Also, remove the unused UDF_PATH_LEN constant. Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 3e7fc20 commit 9fba705

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

fs/udf/namei.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry,
291291
struct udf_fileident_bh fibh;
292292
struct fileIdentDesc *fi;
293293

294-
if (dentry->d_name.len > UDF_NAME_LEN - 2)
294+
if (dentry->d_name.len > UDF_NAME_LEN)
295295
return ERR_PTR(-ENAMETOOLONG);
296296

297297
#ifdef UDF_RECOVERY
@@ -351,7 +351,7 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
351351
struct udf_inode_info *dinfo;
352352

353353
fibh->sbh = fibh->ebh = NULL;
354-
name = kmalloc(UDF_NAME_LEN, GFP_NOFS);
354+
name = kmalloc(UDF_NAME_LEN_CS0, GFP_NOFS);
355355
if (!name) {
356356
*err = -ENOMEM;
357357
goto out_err;
@@ -364,7 +364,7 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
364364
}
365365
namelen = udf_put_filename(sb, dentry->d_name.name,
366366
dentry->d_name.len,
367-
name, UDF_NAME_LEN);
367+
name, UDF_NAME_LEN_CS0);
368368
if (!namelen) {
369369
*err = -ENAMETOOLONG;
370370
goto out_err;
@@ -915,7 +915,7 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
915915

916916
iinfo = UDF_I(inode);
917917
down_write(&iinfo->i_data_sem);
918-
name = kmalloc(UDF_NAME_LEN, GFP_NOFS);
918+
name = kmalloc(UDF_NAME_LEN_CS0, GFP_NOFS);
919919
if (!name) {
920920
err = -ENOMEM;
921921
goto out_no_entry;
@@ -1000,7 +1000,7 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
10001000
if (pc->componentType == 5) {
10011001
namelen = udf_put_filename(sb, compstart,
10021002
symname - compstart,
1003-
name, UDF_NAME_LEN);
1003+
name, UDF_NAME_LEN_CS0);
10041004
if (!namelen)
10051005
goto out_no_entry;
10061006

fs/udf/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2358,7 +2358,7 @@ static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
23582358
le32_to_cpu(lvidiu->numDirs)) : 0)
23592359
+ buf->f_bfree;
23602360
buf->f_ffree = buf->f_bfree;
2361-
buf->f_namelen = UDF_NAME_LEN - 2;
2361+
buf->f_namelen = UDF_NAME_LEN;
23622362
buf->f_fsid.val[0] = (u32)id;
23632363
buf->f_fsid.val[1] = (u32)(id >> 32);
23642364

fs/udf/udfdecl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ extern __printf(3, 4) void _udf_warn(struct super_block *sb,
4949
#define UDF_EXTENT_FLAG_MASK 0xC0000000
5050

5151
#define UDF_NAME_PAD 4
52-
#define UDF_NAME_LEN 256
53-
#define UDF_PATH_LEN 1023
52+
#define UDF_NAME_LEN 254
53+
#define UDF_NAME_LEN_CS0 255
5454

5555
static inline size_t udf_file_entry_alloc_offset(struct inode *inode)
5656
{
@@ -108,7 +108,7 @@ struct generic_desc {
108108

109109
struct ustr {
110110
uint8_t u_cmpID;
111-
uint8_t u_name[UDF_NAME_LEN - 2];
111+
uint8_t u_name[UDF_NAME_LEN];
112112
uint8_t u_len;
113113
};
114114

fs/udf/unicode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static int udf_translate_to_linux(uint8_t *, int, uint8_t *, int, uint8_t *,
3333

3434
static int udf_char_to_ustr(struct ustr *dest, const uint8_t *src, int strlen)
3535
{
36-
if ((!dest) || (!src) || (!strlen) || (strlen > UDF_NAME_LEN - 2))
36+
if ((!dest) || (!src) || (!strlen) || (strlen > UDF_NAME_LEN))
3737
return 0;
3838

3939
memset(dest, 0, sizeof(struct ustr));
@@ -184,14 +184,14 @@ static int udf_name_from_CS0(struct ustr *utf_o,
184184

185185
ocu = ocu_i->u_name;
186186
utf_o->u_len = 0;
187-
for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN - 3));) {
187+
for (i = 0; (i < ocu_len) && (utf_o->u_len < UDF_NAME_LEN);) {
188188
/* Expand OSTA compressed Unicode to Unicode */
189189
uint32_t c = ocu[i++];
190190
if (cmp_id == 16)
191191
c = (c << 8) | ocu[i++];
192192

193193
len = conv_f(c, &utf_o->u_name[utf_o->u_len],
194-
UDF_NAME_LEN - 2 - utf_o->u_len);
194+
UDF_NAME_LEN - utf_o->u_len);
195195
/* Valid character? */
196196
if (len >= 0)
197197
utf_o->u_len += len;

0 commit comments

Comments
 (0)