]> git.street.me.uk Git - andy/viking.git/commitdiff
Fix crashing when displayed map copyright(s) is longer than the internal buffer.
authorRob Norris <rw_norris@hotmail.com>
Thu, 28 Jun 2012 18:37:06 +0000 (19:37 +0100)
committerRob Norris <rw_norris@hotmail.com>
Thu, 28 Jun 2012 18:37:06 +0000 (19:37 +0100)
Ensure strings used are limited to the size of the buffer.

src/vikviewport.c

index 809950fc0d4c626329555cd58597888c6f942af3..ce194c0a5b4ee220bb8609dadc32b0f4c7a5b96f 100644 (file)
@@ -551,11 +551,25 @@ void vik_viewport_draw_copyright ( VikViewport *vvp )
 
   /* compute copyrights string */
   guint len = g_slist_length ( vvp->copyrights );
+
   int i;
   for (i = 0 ; i < len ; i++)
   {
+    // Stop when buffer is full
+    int slen = strlen ( s );
+    if ( slen >= 127 )
+      break;
+
     gchar *copyright = g_slist_nth_data ( vvp->copyrights, i );
-    strcat ( s, copyright );
+
+    // Only use part of this copyright that fits in the available space left
+    //  remembering 1 character is left available for the appended space
+    int clen = strlen ( copyright );
+    if ( slen + clen > 126 ) {
+      clen = 126 - slen;
+    }
+
+    strncat ( s, copyright, clen );
     strcat ( s, " " );
   }