[network-manager-applet] editor: fix reading uninitialized memory



commit e9c8c6a35f66293833d456c41c6599fdbea34f96
Author: Dan Williams <dcbw redhat com>
Date:   Wed Apr 13 15:15:29 2011 -0500

    editor: fix reading uninitialized memory
    
    Need to allocate space for the C string terminator and set it
    to 0.

 src/connection-editor/ip4-routes-dialog.c |    4 +++-
 src/connection-editor/ip6-routes-dialog.c |    4 +++-
 src/connection-editor/page-ip4.c          |    4 +++-
 src/connection-editor/page-ip6.c          |    4 +++-
 src/connection-editor/page-mobile.c       |    4 +++-
 src/wireless-security/ws-wep-key.c        |   24 ++++++++++++------------
 6 files changed, 27 insertions(+), 17 deletions(-)
---
diff --git a/src/connection-editor/ip4-routes-dialog.c b/src/connection-editor/ip4-routes-dialog.c
index 027f054..2117482 100644
--- a/src/connection-editor/ip4-routes-dialog.c
+++ b/src/connection-editor/ip4-routes-dialog.c
@@ -319,7 +319,9 @@ ip_address_filter_cb (GtkEntry *   entry,
 	GtkWidget *ok_button = user_data;
 	GtkEditable *editable = GTK_EDITABLE (entry);
 	int i, count = 0;
-	gchar *result = g_new (gchar, length);
+	gchar *result;
+
+	result = g_malloc0 (length + 1);
 
 	for (i = 0; i < length; i++) {
 		if ((text[i] >= '0' && text[i] <= '9') || (text[i] == '.'))
diff --git a/src/connection-editor/ip6-routes-dialog.c b/src/connection-editor/ip6-routes-dialog.c
index e751300..a8456bd 100644
--- a/src/connection-editor/ip6-routes-dialog.c
+++ b/src/connection-editor/ip6-routes-dialog.c
@@ -276,7 +276,9 @@ ip_address_filter_cb (GtkEntry *   entry,
 	GtkWidget *ok_button = user_data;
 	GtkEditable *editable = GTK_EDITABLE (entry);
 	int i, count = 0;
-	gchar *result = g_new (gchar, length);
+	gchar *result;
+
+	result = g_malloc0 (length + 1);
 
 	for (i = 0; i < length; i++) {
 		if (g_ascii_isxdigit(text[i]) || (text[i] == ':'))
diff --git a/src/connection-editor/page-ip4.c b/src/connection-editor/page-ip4.c
index 2652634..7783db5 100644
--- a/src/connection-editor/page-ip4.c
+++ b/src/connection-editor/page-ip4.c
@@ -600,7 +600,9 @@ ip_address_filter_cb (GtkEntry *   entry,
 	CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (self);
 	GtkEditable *editable = GTK_EDITABLE (entry);
 	int i, count = 0;
-	gchar *result = g_new0 (gchar, length);
+	gchar *result;
+
+	result = g_malloc0 (length + 1);
 
 	for (i = 0; i < length; i++) {
 		if ((text[i] >= '0' && text[i] <= '9') || (text[i] == '.'))
diff --git a/src/connection-editor/page-ip6.c b/src/connection-editor/page-ip6.c
index e027620..80a82f8 100644
--- a/src/connection-editor/page-ip6.c
+++ b/src/connection-editor/page-ip6.c
@@ -573,9 +573,11 @@ ip_address_filter_cb (GtkEntry *   entry,
 	GtkEditable *editable = GTK_EDITABLE (entry);
 	gboolean numeric = FALSE;
 	int i, count = 0;
-	gchar *result = g_new0 (gchar, length);
+	gchar *result;
 	guint column;
 
+	result = g_malloc0 (length + 1);
+
 	/* The prefix column only allows numbers, no ':' */
 	column = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (editable), "column"));
 	if (column == COL_PREFIX)
diff --git a/src/connection-editor/page-mobile.c b/src/connection-editor/page-mobile.c
index 044cb31..348515c 100644
--- a/src/connection-editor/page-mobile.c
+++ b/src/connection-editor/page-mobile.c
@@ -265,7 +265,9 @@ network_id_filter_cb (GtkEntry *   entry,
 {
 	GtkEditable *editable = GTK_EDITABLE (entry);
 	int i, count = 0;
-	gchar *result = g_new0 (gchar, length);
+	gchar *result;
+
+	result = g_malloc0 (length + 1);
 
 	for (i = 0; i < length; i++) {
 		if (isdigit (text[i]))
diff --git a/src/wireless-security/ws-wep-key.c b/src/wireless-security/ws-wep-key.c
index 50f7acb..72c8dc4 100644
--- a/src/wireless-security/ws-wep-key.c
+++ b/src/wireless-security/ws-wep-key.c
@@ -188,7 +188,9 @@ wep_entry_filter_cb (GtkEntry *   entry,
 	WirelessSecurityWEPKey *sec = (WirelessSecurityWEPKey *) data;
 	GtkEditable *editable = GTK_EDITABLE (entry);
 	int i, count = 0;
-	gchar *result = g_new (gchar, length);
+	gchar *result;
+
+	result = g_malloc0 (length + 1);
 
 	if (sec->type == NM_WEP_KEY_TYPE_KEY) {
 		for (i = 0; i < length; i++) {
@@ -200,18 +202,16 @@ wep_entry_filter_cb (GtkEntry *   entry,
 			result[count++] = text[i];
 	}
 
-	if (count == 0)
-		goto out;
-
-	g_signal_handlers_block_by_func (G_OBJECT (editable),
-	                                 G_CALLBACK (wep_entry_filter_cb),
-	                                 data);
-	gtk_editable_insert_text (editable, result, count, position);
-	g_signal_handlers_unblock_by_func (G_OBJECT (editable),
-	                                   G_CALLBACK (wep_entry_filter_cb),
-	                                   data);
+	if (count > 0) {
+		g_signal_handlers_block_by_func (G_OBJECT (editable),
+			                             G_CALLBACK (wep_entry_filter_cb),
+			                             data);
+		gtk_editable_insert_text (editable, result, count, position);
+		g_signal_handlers_unblock_by_func (G_OBJECT (editable),
+			                               G_CALLBACK (wep_entry_filter_cb),
+			                               data);
+	}
 
-out:
 	g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text");
 	g_free (result);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]