Fix a crash when a resource contains non-representable chars
authorMikael Berthe <mikael@lilotux.net>
Fri, 30 Dec 2005 12:46:48 +0100
changeset 642 ebbe3845b46b
parent 641 62679532ea55
child 643 dd73c3dad815
Fix a crash when a resource contains non-representable chars
mcabber/src/jabglue.c
--- a/mcabber/src/jabglue.c	Wed Dec 28 19:05:11 2005 +0100
+++ b/mcabber/src/jabglue.c	Fri Dec 30 12:46:48 2005 +0100
@@ -1394,14 +1394,20 @@
     if (m++) {
       s = from_utf8(m);
       if (s) {
-        // The length should be enough because from_utf should only
-        // reduce the string length
+        // In some cases the allocated memory size could be too small because
+        // when chars cannot be converted strings like "\uxxxx" or "\Uxxxxyyyy"
+        // are used.
+        if (strlen(r+1) < strlen(s)) {
+          from = g_realloc(from, 1+m-p+strlen(s));
+          r = strchr(from, '/');
+        }
         strcpy(r+1, s);
         g_free(s);
       } else {
         *(r+1) = 0;
         scr_LogPrint(LPRINT_NORMAL, "Decoding of message sender has failed");
-        scr_LogPrint(LPRINT_LOG, "Decoding of message sender has failed: %s", m);
+        scr_LogPrint(LPRINT_LOG, "Decoding of message sender has failed: %s",
+                     m);
       }
     }
   }