From 4e3a242f2fe32230819eb175b55e62e9934cbf8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Garc=C3=ADa=20S=C3=A1ez?= Date: Thu, 31 Jul 2014 20:44:14 +0200 Subject: [PATCH] oc-rtf: Don't crash when we don't know the specified font --- OpenChange/RTFHandler.m | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/OpenChange/RTFHandler.m b/OpenChange/RTFHandler.m index 1e15ebaa8..5cc619b49 100644 --- a/OpenChange/RTFHandler.m +++ b/OpenChange/RTFHandler.m @@ -814,20 +814,28 @@ const unsigned short ansicpg874[256] = { if (!formattingOptions) continue; - + if (formattingOptions->font_index >= 0 && font_index != formattingOptions->font_index) { [_html appendBytes: "" length: 7]; } - + formattingOptions->font_index = font_index; fontInfo = [fontTable fontInfoAtIndex: font_index]; - - char *v = malloc(128*sizeof(char)); - memset(v, 0, 128); - sprintf(v, "", [fontInfo->name UTF8String]); + char *v = calloc(128, sizeof(char)); + if (fontInfo) + { + sprintf(v, "", [fontInfo->name UTF8String]); + } + else + { + // RTF badformed? We don't know about that font (font_index). + // Anyhow, we still open the html tag because in the future + // we will close it (e.g. when new font is used). + sprintf(v, ""); + } [_html appendBytes: v length: strlen(v)]; free(v); }