[Commits] [SCM] claws branch, gtk3, updated. 4.0.0-389-g1a9ec36b0

miras at claws-mail.org miras at claws-mail.org
Sat Dec 25 21:44:50 UTC 2021


The branch, gtk3 has been updated
       via  1a9ec36b0a3a29b6ad2397d2741fcb080d51fba3 (commit)
       via  156003b4bd1b6d638d726dec42af60bda6046e1c (commit)
      from  3afec966fdd14a2eee0c0ab4254169ba42ee4674 (commit)

Summary of changes:
 src/common/utils.h | 25 ++++++++++++++++++++++++-
 src/compose.c      | 21 ++++++++++++++++++++-
 2 files changed, 44 insertions(+), 2 deletions(-)


- Log -----------------------------------------------------------------
commit 1a9ec36b0a3a29b6ad2397d2741fcb080d51fba3
Author: Michael Rasmussen <mir at datanom.net>
Date:   Sat Dec 25 22:44:38 2021 +0100

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

diff --git a/src/compose.c b/src/compose.c
index 0011a5e75..a1e60d333 100644
--- a/src/compose.c
+++ b/src/compose.c
@@ -10868,6 +10868,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)
 {
@@ -10880,7 +10894,12 @@ static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
  
 		if (contents == NULL)
 			return;
-	
+
+                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) {

commit 156003b4bd1b6d638d726dec42af60bda6046e1c
Author: Michael Rasmussen <mir at datanom.net>
Date:   Sat Dec 25 22:42:50 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..8d7ed89fc 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -95,8 +95,18 @@ 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 (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; \
@@ -106,8 +116,13 @@ typedef gint64 goffset;
 #define Xstrdup_a(ptr, str, iffail) \
 { \
 	gchar *__tmp; \
+        ssize_t size = strlen(str); \
  \
-	if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
+        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 \
@@ -120,6 +135,10 @@ typedef gint64 goffset;
 { \
 	gchar *__tmp; \
  \
+        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; \
@@ -138,6 +157,10 @@ typedef gint64 goffset;
  \
 	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; \

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


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list