]> git.eshelyaron.com Git - emacs.git/commitdiff
* nsfns.m (Fns_convert_utf8_nfd_to_nfc): Check input for valid UTF-8
authorJan Djärv <jan.h.d@swipnet.se>
Wed, 9 Oct 2013 18:50:14 +0000 (20:50 +0200)
committerJan Djärv <jan.h.d@swipnet.se>
Wed, 9 Oct 2013 18:50:14 +0000 (20:50 +0200)
or throw error.

Fixes: debbugs:15570
src/ChangeLog
src/nsfns.m

index e4456b2ce2bb6059a52244af7a7a5bec58e4721d..1a05203273f867e925ae6a350b073c2e7d336b89 100644 (file)
@@ -1,3 +1,8 @@
+2013-10-09  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * nsfns.m (Fns_convert_utf8_nfd_to_nfc): Check input for valid UTF-8
+       or throw error (Bug#15570).
+
 2013-10-09  Paul Eggert  <eggert@cs.ucla.edu>
 
        * intervals.c (temp_set_point_both): Move test into 'eassert',
index 93b7d12becb519d509fb29ccb6cf04aa82ab8bbc..24edd4366ce89aff242b6bb8a6c3ac192ca8301e 100644 (file)
@@ -2048,16 +2048,27 @@ DEFUN ("ns-convert-utf8-nfd-to-nfc", Fns_convert_utf8_nfd_to_nfc,
 /* TODO: If GNUstep ever implements precomposedStringWithCanonicalMapping,
          remove this. */
   NSString *utfStr;
-  Lisp_Object ret;
+  Lisp_Object ret = Qnil;
+  NSAutoreleasePool *pool;
 
   CHECK_STRING (str);
-  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- utfStr = [NSString stringWithUTF8String: SSDATA (str)];
+  pool = [[NSAutoreleasePool alloc] init];
 utfStr = [NSString stringWithUTF8String: SSDATA (str)];
 #ifdef NS_IMPL_COCOA
-  utfStr = [utfStr precomposedStringWithCanonicalMapping];
+  if (utfStr)
+    utfStr = [utfStr precomposedStringWithCanonicalMapping];
 #endif
-  ret = build_string ([utfStr UTF8String]);
+  if (utfStr)
+    {
+      const char *cstr = [utfStr UTF8String];
+      if (cstr)
+        ret = build_string (cstr);
+    }
+
   [pool release];
+  if (NILP (ret))
+    error ("Invalid UTF-8");
+
   return ret;
 }