[cairo] [PATCH] Ensure null-terminated result from strncpy()

Bryce Harrington bryce at osg.samsung.com
Fri Aug 28 13:25:21 PDT 2015


Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
---
 src/cairo-scaled-font-subsets.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/cairo-scaled-font-subsets.c b/src/cairo-scaled-font-subsets.c
index 2121761..196fa99 100644
--- a/src/cairo-scaled-font-subsets.c
+++ b/src/cairo-scaled-font-subsets.c
@@ -1206,10 +1206,12 @@ _cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset
 
 	if (utf16_len == 1) {
 	    int ch = _cairo_unicode_to_winansi (utf16[0]);
-	    if (ch > 0 && _cairo_winansi_to_glyphname (ch))
+	    if (ch > 0 && _cairo_winansi_to_glyphname (ch)) {
 		strncpy (buf, _cairo_winansi_to_glyphname (ch), sizeof (buf));
-	    else
+		buf[sizeof (buf)-1] = '\0';
+	    } else {
 		snprintf (buf, sizeof (buf), "uni%04X", (int) utf16[0]);
+	    }
 
 	    _cairo_string_init_key (&key, buf);
 	    entry = _cairo_hash_table_lookup (names, &key.base);
-- 
1.9.1



More information about the cairo mailing list