Skip to content

Commit c36f9d7

Browse files
Wer-Wolfij-intel
authored andcommitted
fs/nls: Fix inconsistency between utf8_to_utf32() and utf32_to_utf8()
After commit 25524b6 ("fs/nls: Fix utf16 to utf8 conversion"), the return values of utf8_to_utf32() and utf32_to_utf8() are inconsistent when encountering an error: utf8_to_utf32() returns -1, while utf32_to_utf8() returns errno codes. Fix this inconsistency by modifying utf8_to_utf32() to return errno codes as well. Fixes: 25524b6 ("fs/nls: Fix utf16 to utf8 conversion") Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Signed-off-by: Armin Wolf <W_Armin@gmx.de> Link: https://patch.msgid.link/20251129111535.8984-1-W_Armin@gmx.de Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
1 parent 859d4ce commit c36f9d7

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

fs/nls/nls_base.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,22 @@ int utf8_to_utf32(const u8 *s, int inlen, unicode_t *pu)
6767
l &= t->lmask;
6868
if (l < t->lval || l > UNICODE_MAX ||
6969
(l & SURROGATE_MASK) == SURROGATE_PAIR)
70-
return -1;
70+
return -EILSEQ;
71+
7172
*pu = (unicode_t) l;
7273
return nc;
7374
}
7475
if (inlen <= nc)
75-
return -1;
76+
return -EOVERFLOW;
77+
7678
s++;
7779
c = (*s ^ 0x80) & 0xFF;
7880
if (c & 0xC0)
79-
return -1;
81+
return -EILSEQ;
82+
8083
l = (l << 6) | c;
8184
}
82-
return -1;
85+
return -EILSEQ;
8386
}
8487
EXPORT_SYMBOL(utf8_to_utf32);
8588

0 commit comments

Comments
 (0)