address non nul terminated string due to strncpy

this addresses CID 1230994. as such  eina_unicode_unicode_to_utf8()
always returns a nul terminated string. so it's guaranteed. but yes -
if string is 7 bytes or longer it will not put a nul byte on the
destination. as such for a single unicode char this can never happen
as in utf8 it's 6 bytes. but since eina_unicode_unicode_to_utf8()
safely returns a nul terminated string at all times - we can just use
strcpy safely. no need for strncpy. also handle null return from
eina_unicode_unicode_to_utf8()
This commit is contained in:
Carsten Haitzler 2014-08-13 09:03:02 +09:00
parent 2ac4f520d6
commit d539152156
1 changed files with 7 additions and 2 deletions

View File

@ -6137,8 +6137,13 @@ _escaped_char_get(const char *s, const char *s_end)
return NULL;
utf8_char = eina_unicode_unicode_to_utf8(uchar, NULL);
strncpy(utf8_escape, utf8_char, sizeof(utf8_escape));
free(utf8_char);
// eina_unicode_unicode_to_utf8() always creates a string that
// is nul terminated - guaranteed
if (utf8_char)
{
strcpy(utf8_escape, utf8_char);
free(utf8_char);
}
return utf8_escape;
}