From d539152156e50e81e18c3eb226db8095f83bd7d1 Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Wed, 13 Aug 2014 09:03:02 +0900 Subject: [PATCH] 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() --- src/lib/evas/canvas/evas_object_textblock.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c index 930c94be95..ae1466cc6a 100644 --- a/src/lib/evas/canvas/evas_object_textblock.c +++ b/src/lib/evas/canvas/evas_object_textblock.c @@ -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; }