diff options
Diffstat (limited to 'fs/udf/unicode.c')
-rw-r--r-- | fs/udf/unicode.c | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/fs/udf/unicode.c b/fs/udf/unicode.c index b84fee372734..ab478e62baae 100644 --- a/fs/udf/unicode.c +++ b/fs/udf/unicode.c | |||
@@ -68,21 +68,16 @@ int udf_build_ustr(struct ustr *dest, dstring *ptr, int size) | |||
68 | /* | 68 | /* |
69 | * udf_build_ustr_exact | 69 | * udf_build_ustr_exact |
70 | */ | 70 | */ |
71 | static int udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize) | 71 | static void udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize) |
72 | { | 72 | { |
73 | if ((!dest) || (!ptr) || (!exactsize)) | ||
74 | return -1; | ||
75 | |||
76 | memset(dest, 0, sizeof(struct ustr)); | 73 | memset(dest, 0, sizeof(struct ustr)); |
77 | dest->u_cmpID = ptr[0]; | 74 | dest->u_cmpID = ptr[0]; |
78 | dest->u_len = exactsize - 1; | 75 | dest->u_len = exactsize - 1; |
79 | memcpy(dest->u_name, ptr + 1, exactsize - 1); | 76 | memcpy(dest->u_name, ptr + 1, exactsize - 1); |
80 | |||
81 | return 0; | ||
82 | } | 77 | } |
83 | 78 | ||
84 | /* | 79 | /* |
85 | * udf_ocu_to_utf8 | 80 | * udf_CS0toUTF8 |
86 | * | 81 | * |
87 | * PURPOSE | 82 | * PURPOSE |
88 | * Convert OSTA Compressed Unicode to the UTF-8 equivalent. | 83 | * Convert OSTA Compressed Unicode to the UTF-8 equivalent. |
@@ -94,7 +89,7 @@ static int udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize) | |||
94 | * both of type "struct ustr *" | 89 | * both of type "struct ustr *" |
95 | * | 90 | * |
96 | * POST-CONDITIONS | 91 | * POST-CONDITIONS |
97 | * <return> Zero on success. | 92 | * <return> >= 0 on success. |
98 | * | 93 | * |
99 | * HISTORY | 94 | * HISTORY |
100 | * November 12, 1997 - Andrew E. Mileski | 95 | * November 12, 1997 - Andrew E. Mileski |
@@ -117,7 +112,7 @@ int udf_CS0toUTF8(struct ustr *utf_o, const struct ustr *ocu_i) | |||
117 | memset(utf_o, 0, sizeof(struct ustr)); | 112 | memset(utf_o, 0, sizeof(struct ustr)); |
118 | pr_err("unknown compression code (%d) stri=%s\n", | 113 | pr_err("unknown compression code (%d) stri=%s\n", |
119 | cmp_id, ocu_i->u_name); | 114 | cmp_id, ocu_i->u_name); |
120 | return 0; | 115 | return -EINVAL; |
121 | } | 116 | } |
122 | 117 | ||
123 | ocu = ocu_i->u_name; | 118 | ocu = ocu_i->u_name; |
@@ -154,7 +149,7 @@ int udf_CS0toUTF8(struct ustr *utf_o, const struct ustr *ocu_i) | |||
154 | 149 | ||
155 | /* | 150 | /* |
156 | * | 151 | * |
157 | * udf_utf8_to_ocu | 152 | * udf_UTF8toCS0 |
158 | * | 153 | * |
159 | * PURPOSE | 154 | * PURPOSE |
160 | * Convert UTF-8 to the OSTA Compressed Unicode equivalent. | 155 | * Convert UTF-8 to the OSTA Compressed Unicode equivalent. |
@@ -270,7 +265,7 @@ static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o, | |||
270 | memset(utf_o, 0, sizeof(struct ustr)); | 265 | memset(utf_o, 0, sizeof(struct ustr)); |
271 | pr_err("unknown compression code (%d) stri=%s\n", | 266 | pr_err("unknown compression code (%d) stri=%s\n", |
272 | cmp_id, ocu_i->u_name); | 267 | cmp_id, ocu_i->u_name); |
273 | return 0; | 268 | return -EINVAL; |
274 | } | 269 | } |
275 | 270 | ||
276 | ocu = ocu_i->u_name; | 271 | ocu = ocu_i->u_name; |
@@ -338,43 +333,51 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen, | |||
338 | uint8_t *dname, int dlen) | 333 | uint8_t *dname, int dlen) |
339 | { | 334 | { |
340 | struct ustr *filename, *unifilename; | 335 | struct ustr *filename, *unifilename; |
341 | int len = 0; | 336 | int ret; |
337 | |||
338 | if (!slen) | ||
339 | return -EIO; | ||
342 | 340 | ||
343 | filename = kmalloc(sizeof(struct ustr), GFP_NOFS); | 341 | filename = kmalloc(sizeof(struct ustr), GFP_NOFS); |
344 | if (!filename) | 342 | if (!filename) |
345 | return 0; | 343 | return -ENOMEM; |
346 | 344 | ||
347 | unifilename = kmalloc(sizeof(struct ustr), GFP_NOFS); | 345 | unifilename = kmalloc(sizeof(struct ustr), GFP_NOFS); |
348 | if (!unifilename) | 346 | if (!unifilename) { |
347 | ret = -ENOMEM; | ||
349 | goto out1; | 348 | goto out1; |
349 | } | ||
350 | 350 | ||
351 | if (udf_build_ustr_exact(unifilename, sname, slen)) | 351 | udf_build_ustr_exact(unifilename, sname, slen); |
352 | goto out2; | ||
353 | |||
354 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { | 352 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { |
355 | if (!udf_CS0toUTF8(filename, unifilename)) { | 353 | ret = udf_CS0toUTF8(filename, unifilename); |
354 | if (ret < 0) { | ||
356 | udf_debug("Failed in udf_get_filename: sname = %s\n", | 355 | udf_debug("Failed in udf_get_filename: sname = %s\n", |
357 | sname); | 356 | sname); |
358 | goto out2; | 357 | goto out2; |
359 | } | 358 | } |
360 | } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { | 359 | } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { |
361 | if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, filename, | 360 | ret = udf_CS0toNLS(UDF_SB(sb)->s_nls_map, filename, |
362 | unifilename)) { | 361 | unifilename); |
362 | if (ret < 0) { | ||
363 | udf_debug("Failed in udf_get_filename: sname = %s\n", | 363 | udf_debug("Failed in udf_get_filename: sname = %s\n", |
364 | sname); | 364 | sname); |
365 | goto out2; | 365 | goto out2; |
366 | } | 366 | } |
367 | } else | 367 | } else |
368 | goto out2; | 368 | BUG(); |
369 | 369 | ||
370 | len = udf_translate_to_linux(dname, dlen, | 370 | ret = udf_translate_to_linux(dname, dlen, |
371 | filename->u_name, filename->u_len, | 371 | filename->u_name, filename->u_len, |
372 | unifilename->u_name, unifilename->u_len); | 372 | unifilename->u_name, unifilename->u_len); |
373 | /* Zero length filename isn't valid... */ | ||
374 | if (ret == 0) | ||
375 | ret = -EINVAL; | ||
373 | out2: | 376 | out2: |
374 | kfree(unifilename); | 377 | kfree(unifilename); |
375 | out1: | 378 | out1: |
376 | kfree(filename); | 379 | kfree(filename); |
377 | return len; | 380 | return ret; |
378 | } | 381 | } |
379 | 382 | ||
380 | int udf_put_filename(struct super_block *sb, const uint8_t *sname, | 383 | int udf_put_filename(struct super_block *sb, const uint8_t *sname, |