summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2022-05-27 13:22:22 -0700
committerKevin McCarthy <kevin@8t8.us>2022-05-27 14:15:28 -0700
commitdef28317711dacf45dfbad760d952b70aaf27a58 (patch)
tree4aec134d66dd34c282294c9bda05a7b7d5f403ac
parent51c67ba95bd1faabd4ef486de0fb862630a9e3ae (diff)
Fix mbrtowc() error handling in check_alias_name().
The function did not reset the increment value on any error. Increase the maximum conversion size to the string length, and check for -2. Since we're looking at the whole string, we can then just terminate the loop on a -2 return value.
-rw-r--r--alias.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/alias.c b/alias.c
index 5ff2acc2..60bee356 100644
--- a/alias.c
+++ b/alias.c
@@ -425,16 +425,17 @@ static int check_alias_name (const char *s, BUFFER *dest)
{
wchar_t wc;
mbstate_t mb;
- size_t l;
+ size_t l, n;
int rv = 0, bad = 0, dry = !dest;
memset (&mb, 0, sizeof (mbstate_t));
+ n = mutt_strlen (s);
if (!dry)
mutt_buffer_clear (dest);
- for (; s && *s &&
- (l = mbrtowc (&wc, s, MB_CUR_MAX, &mb)) != 0;
- s += l)
+ for (; s && *s && n &&
+ (l = mbrtowc (&wc, s, n, &mb)) != 0;
+ s += l, n-= l)
{
bad = l == (size_t)(-1) || l == (size_t)(-2); /* conversion error */
if (l == 1)
@@ -446,7 +447,12 @@ static int check_alias_name (const char *s, BUFFER *dest)
if (dry)
return -1;
if (l == (size_t)(-1))
+ {
memset (&mb, 0, sizeof (mbstate_t));
+ l = 1;
+ }
+ if (l == (size_t)(-2))
+ l = n;
mutt_buffer_addch (dest, '_');
rv = -1;
}