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



commit 5c4a45b1153eed2f1e6f0e7553cee88a8bf735cf
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 fc8f487..f77fdc2 100644
--- a/src/connection-editor/ip4-routes-dialog.c
+++ b/src/connection-editor/ip4-routes-dialog.c
@@ -317,7 +317,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 65432e4..a8acf22 100644
--- a/src/connection-editor/ip6-routes-dialog.c
+++ b/src/connection-editor/ip6-routes-dialog.c
@@ -274,7 +274,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 6492366..dca7392 100644
--- a/src/connection-editor/page-ip4.c
+++ b/src/connection-editor/page-ip4.c
@@ -601,7 +601,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 320199c..890d935 100644
--- a/src/connection-editor/page-ip6.c
+++ b/src/connection-editor/page-ip6.c
@@ -574,9 +574,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 afe2fab..1ef4b44 100644
--- a/src/connection-editor/page-mobile.c
+++ b/src/connection-editor/page-mobile.c
@@ -258,7 +258,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 ba5ca01..438c81c 100644
--- a/src/wireless-security/ws-wep-key.c
+++ b/src/wireless-security/ws-wep-key.c
@@ -190,7 +190,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++) {
@@ -202,18 +204,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]