From 081fc4e70196f158730b5c3628a11db7dff2c375 Mon Sep 17 00:00:00 2001 From: Wolfgang Lux Date: Fri, 18 Jun 2010 17:03:55 +0000 Subject: [PATCH] Avoid potential illegal access violation introduced with the previous commit. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@30775 72102866-910b-0410-8b05-ffd578937521 --- Source/NSAttributedString.m | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/Source/NSAttributedString.m b/Source/NSAttributedString.m index 096ea5e15..bc6b85b80 100644 --- a/Source/NSAttributedString.m +++ b/Source/NSAttributedString.m @@ -766,25 +766,31 @@ create_error(int code, NSString* desc) if (type == nil) { - const void *dataBytes = [data bytes]; + // Make sure this buffer is long enough + char prefix[14]; + NSUInteger l = [data length]; + if (l < sizeof(prefix)) + { + [data getBytes: prefix length: l]; + prefix[l] = 0; + } + else + { + [data getBytes: prefix length: sizeof(prefix)]; + } // The list of file types below was derived from Apache's conf/magic file // FIXME extend the list - if (strncmp(dataBytes, "{\\rtf", 5) == 0) + if (strncmp(prefix, "{\\rtf", 5) == 0) { type = NSRTFTextDocumentType; } - else if (strncmp(dataBytes, "