[Commits] [SCM] claws branch, master, updated. 3.18.0-305-g4e10965ee

miras at claws-mail.org miras at claws-mail.org
Sat Dec 25 22:08:52 UTC 2021


The branch, master has been updated
       via  4e10965ee27426d10f74a2cae062e06e69073958 (commit)
       via  f9fa10468c97f9498ece9bca5796cfa7b100499b (commit)
      from  cbf024d6e0abf27f20ba71fc62e216806fc57df3 (commit)

Summary of changes:
 src/common/utils.h | 95 +++++++++++++++++++++++++++++++++---------------------
 src/compose.c      | 24 ++++++++++++--
 2 files changed, 81 insertions(+), 38 deletions(-)


- Log -----------------------------------------------------------------
commit 4e10965ee27426d10f74a2cae062e06e69073958
Author: Michael Rasmussen <mir at datanom.net>
Date:   Sat Dec 25 23:08:38 2021 +0100

    Warn when user tries to paste more text into compose window than the defined max size in common/utils.h
    
    Signed-off-by: Michael Rasmussen <mir at datanom.net>

diff --git a/src/compose.c b/src/compose.c
index e00ab8310..985ec30ba 100644
--- a/src/compose.c
+++ b/src/compose.c
@@ -10896,6 +10896,20 @@ static void entry_copy_clipboard(GtkWidget *entry)
 			gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
 }
 
+static void text_to_big_alert(Compose *compose, glong size) {
+        GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
+        GtkMessageDialog* dialog = gtk_message_dialog_new(
+                                        GTK_WINDOW(compose->window),
+                                        flags,
+                                        GTK_MESSAGE_INFO,
+                                        GTK_BUTTONS_OK,
+                                        _("Number of pages '%d' exceeds limit '%d' for paste. Attach as file instead"),
+                                        (size / 1800),
+                                        (MAX_ALLOCA_MEM_SIZE / 1800));
+        gtk_dialog_run(GTK_DIALOG(dialog));
+        gtk_widget_destroy(GTK_WIDGET(dialog));
+}
+
 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, 
  				  gboolean wrap, GdkAtom clip, GtkTextIter *insert_place)
 {
@@ -10908,8 +10922,14 @@ static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
  
 		if (contents == NULL)
 			return;
-	
-		/* we shouldn't delete the selection when middle-click-pasting, or we
+
+                glong len = g_utf8_strlen(contents, -1);
+                if (len > MAX_ALLOCA_MEM_SIZE) {
+                        text_to_big_alert(compose, len);
+                        return;
+                }
+
+                /* we shouldn't delete the selection when middle-click-pasting, or we
 		 * can't mid-click-paste our own selection */
 		if (clip != GDK_SELECTION_PRIMARY) {
 			undo_paste_clipboard(GTK_TEXT_VIEW(compose->text), compose->undostruct);

commit f9fa10468c97f9498ece9bca5796cfa7b100499b
Author: Michael Rasmussen <mir at datanom.net>
Date:   Sat Dec 25 23:00:21 2021 +0100

    Protect alloca function to not request a memory size larger than the stack frame size - Causing segmentation faults
    
    Signed-off-by: Michael Rasmussen <mir at datanom.net>

diff --git a/src/common/utils.h b/src/common/utils.h
index 1010aa87c..3e378e5ea 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -95,66 +95,89 @@ typedef gint64 goffset;
 	} \
 }
 
+/*
+100k of utf-8 text is 51200 utf-8 characters and
+51200 utf-8 characters is at least 28 A4 pages
+*/
+#define MAX_ALLOCA_MEM_SIZE 51200
+
 #define Xalloca(ptr, size, iffail) \
 { \
-	if ((ptr = alloca(size)) == NULL) { \
-		g_warning("can't allocate memory"); \
-		iffail; \
-	} \
+        if (size > MAX_ALLOCA_MEM_SIZE) { \
+                g_warning("%ld: Exceeds max allowed memory '%d'", size, MAX_ALLOCA_MEM_SIZE); \
+                iffail; \
+        } \
+        if ((ptr = alloca(size)) == NULL) { \
+                g_warning("can't allocate memory"); \
+                iffail; \
+        } \
 }
 
 #define Xstrdup_a(ptr, str, iffail) \
 { \
-	gchar *__tmp; \
+        gchar *__tmp; \
+        ssize_t size = strlen(str); \
  \
-	if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
-		g_warning("can't allocate memory"); \
-		iffail; \
-	} else \
-		strcpy(__tmp, str); \
+        if (size > MAX_ALLOCA_MEM_SIZE) { \
+                g_warning("%ld: Exceeds max allowed memory '%d'", size, MAX_ALLOCA_MEM_SIZE); \
+                iffail; \
+        } \
+        if ((__tmp = alloca(size + 1)) == NULL) { \
+                g_warning("can't allocate memory"); \
+                iffail; \
+        } else \
+                strcpy(__tmp, str); \
  \
-	ptr = __tmp; \
+        ptr = __tmp; \
 }
 
 #define Xstrndup_a(ptr, str, len, iffail) \
 { \
-	gchar *__tmp; \
+        gchar *__tmp; \
  \
-	if ((__tmp = alloca(len + 1)) == NULL) { \
-		g_warning("can't allocate memory"); \
-		iffail; \
-	} else { \
-		memcpy(__tmp, str, len); \
-		__tmp[len] = '\0'; \
-	} \
+        if (len > MAX_ALLOCA_MEM_SIZE) { \
+                g_warning("%ld: Exceeds max allowed memory '%d'", len, MAX_ALLOCA_MEM_SIZE); \
+                iffail; \
+        } \
+        if ((__tmp = alloca(len + 1)) == NULL) { \
+                g_warning("can't allocate memory"); \
+                iffail; \
+        } else { \
+                memcpy(__tmp, str, len); \
+                __tmp[len] = '\0'; \
+        } \
  \
-	ptr = __tmp; \
+        ptr = __tmp; \
 }
 
 #define Xstrcat_a(ptr, str1, str2, iffail) \
 { \
-	gchar *__tmp; \
-	gint len1, len2; \
+        gchar *__tmp; \
+        gint len1, len2; \
  \
-	len1 = strlen(str1); \
-	len2 = strlen(str2); \
-	if ((__tmp = alloca(len1 + len2 + 1)) == NULL) { \
-		g_warning("can't allocate memory"); \
-		iffail; \
-	} else { \
-		memcpy(__tmp, str1, len1); \
-		memcpy(__tmp + len1, str2, len2 + 1); \
-	} \
+        len1 = strlen(str1); \
+        len2 = strlen(str2); \
+        if (len1 + len2 > MAX_ALLOCA_MEM_SIZE) { \
+                g_warning("%ld: Exceeds max allowed memory '%d'", len1 + len2, MAX_ALLOCA_MEM_SIZE); \
+                iffail; \
+        } \
+        if ((__tmp = alloca(len1 + len2 + 1)) == NULL) { \
+                g_warning("can't allocate memory"); \
+                iffail; \
+        } else { \
+                memcpy(__tmp, str1, len1); \
+                memcpy(__tmp + len1, str2, len2 + 1); \
+        } \
  \
-	ptr = __tmp; \
+        ptr = __tmp; \
 }
 
 #define AUTORELEASE_STR(str, iffail) \
 { \
-	gchar *__str; \
-	Xstrdup_a(__str, str, iffail); \
-	g_free(str); \
-	str = __str; \
+        gchar *__str; \
+        Xstrdup_a(__str, str, iffail); \
+        g_free(str); \
+        str = __str; \
 }
 
 #define FILE_OP_ERROR(file, func) \

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list