udf: improve error management in udf_CS0toUTF8()
authorFabian Frederick <fabf@skynet.be>
Wed, 8 Apr 2015 19:23:54 +0000 (21:23 +0200)
committerJan Kara <jack@suse.cz>
Mon, 18 May 2015 09:23:05 +0000 (11:23 +0200)
udf_CS0toUTF8() now returns -EINVAL on error.
udf_load_pvoldesc() and udf_get_filename() do the same.

Suggested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Fabian Frederick <fabf@skynet.be>
Signed-off-by: Jan Kara <jack@suse.cz>
fs/udf/super.c
fs/udf/unicode.c

index 6299f341967baf8e03b4e032b37eda524006e4ce..c6a8f5f794439107ddad9ed4e639449a62586fe5 100644 (file)
@@ -927,17 +927,22 @@ static int udf_load_pvoldesc(struct super_block *sb, sector_t block)
 #endif
        }
 
-       if (!udf_build_ustr(instr, pvoldesc->volIdent, 32))
-               if (udf_CS0toUTF8(outstr, instr)) {
-                       strncpy(UDF_SB(sb)->s_volume_ident, outstr->u_name,
-                               outstr->u_len > 31 ? 31 : outstr->u_len);
-                       udf_debug("volIdent[] = '%s'\n",
-                                 UDF_SB(sb)->s_volume_ident);
-               }
+       if (!udf_build_ustr(instr, pvoldesc->volIdent, 32)) {
+               ret = udf_CS0toUTF8(outstr, instr);
+               if (ret < 0)
+                       goto out_bh;
+
+               strncpy(UDF_SB(sb)->s_volume_ident, outstr->u_name,
+                       outstr->u_len > 31 ? 31 : outstr->u_len);
+               udf_debug("volIdent[] = '%s'\n", UDF_SB(sb)->s_volume_ident);
+       }
 
        if (!udf_build_ustr(instr, pvoldesc->volSetIdent, 128))
-               if (udf_CS0toUTF8(outstr, instr))
-                       udf_debug("volSetIdent[] = '%s'\n", outstr->u_name);
+               ret = udf_CS0toUTF8(outstr, instr);
+               if (ret < 0)
+                       goto out_bh;
+
+               udf_debug("volSetIdent[] = '%s'\n", outstr->u_name);
 
        ret = 0;
 out_bh:
index 41c3bef1d22661cc808e3ac8590b249b6760eb10..35cc9477b066aed431b2352cd49ebb6f05025c79 100644 (file)
@@ -89,7 +89,7 @@ static void udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize)
  *                             both of type "struct ustr *"
  *
  * POST-CONDITIONS
- *     <return>                Zero on success.
+ *     <return>                >= 0 on success.
  *
  * HISTORY
  *     November 12, 1997 - Andrew E. Mileski
@@ -112,7 +112,7 @@ int udf_CS0toUTF8(struct ustr *utf_o, const struct ustr *ocu_i)
                memset(utf_o, 0, sizeof(struct ustr));
                pr_err("unknown compression code (%d) stri=%s\n",
                       cmp_id, ocu_i->u_name);
-               return 0;
+               return -EINVAL;
        }
 
        ocu = ocu_i->u_name;
@@ -350,7 +350,8 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen,
 
        udf_build_ustr_exact(unifilename, sname, slen);
        if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
-               if (!udf_CS0toUTF8(filename, unifilename)) {
+               ret = udf_CS0toUTF8(filename, unifilename);
+               if (ret < 0) {
                        udf_debug("Failed in udf_get_filename: sname = %s\n",
                                  sname);
                        goto out2;