gnome-keyring r1707 - in trunk: . egg



Author: stefw
Date: Thu Apr  2 03:29:59 2009
New Revision: 1707
URL: http://svn.gnome.org/viewvc/gnome-keyring?rev=1707&view=rev

Log:
Add validator which walks the secure memory heap and checks for inconsistencies.

Modified:
   trunk/ChangeLog
   trunk/egg/egg-secure-memory.c
   trunk/egg/egg-secure-memory.h

Modified: trunk/egg/egg-secure-memory.c
==============================================================================
--- trunk/egg/egg-secure-memory.c	(original)
+++ trunk/egg/egg-secure-memory.c	Thu Apr  2 03:29:59 2009
@@ -350,6 +350,8 @@
 	}
 	
 	*ring = cell;
+	ASSERT (cell->next->prev == cell);
+	ASSERT (cell->prev->next == cell);
 }
 
 static void
@@ -359,7 +361,10 @@
 	ASSERT (*ring);
 	ASSERT (cell->next);
 	ASSERT (cell->prev);
-	
+
+	ASSERT (cell->next->prev == cell);
+	ASSERT (cell->prev->next == cell);
+
 	if (cell == *ring) {
 		/* The last meta? */
 		if (cell->next == cell) {
@@ -727,6 +732,45 @@
 	return cell->allocated;
 }
 
+static void
+sec_validate (Block *block)
+{
+	Cell *cell;
+	word_t *word, *last;
+	
+	word = block->words;
+	last = word + block->n_words;
+
+	for (;;) {
+		ASSERT (word < last);
+
+		ASSERT (sec_is_valid_word (block, word));
+		ASSERT (pool_valid (*word));
+		cell = *word;
+	
+		/* Validate that it's actually for real */
+		sec_check_guards (cell);
+	
+		/* Is it an allocated block? */
+		if (cell->allocated > 0) {
+			ASSERT (cell->next == NULL);
+			ASSERT (cell->prev == NULL);
+			ASSERT (cell->allocated <= (cell->n_words - 2) * sizeof (word_t));
+		
+			/* An unused block */
+		} else {
+			ASSERT (cell->next);
+			ASSERT (cell->prev);
+			ASSERT (cell->next->prev == cell);
+			ASSERT (cell->prev->next == cell);
+		}
+		
+		word += cell->n_words;
+		if (word == last)
+			break;
+	}
+}
+
 /* -----------------------------------------------------------------------------
  * LOCKED MEMORY
  */
@@ -1104,6 +1148,19 @@
 } 
 
 void
+egg_secure_validate (void)
+{
+	Block *block = NULL;
+	
+	DO_LOCK ();
+	
+		for (block = all_blocks; block; block = block->next)
+			sec_validate (block);
+		
+	DO_UNLOCK ();
+}
+
+void
 egg_secure_dump_blocks (void)
 {
 	Block *block = NULL;

Modified: trunk/egg/egg-secure-memory.h
==============================================================================
--- trunk/egg/egg-secure-memory.h	(original)
+++ trunk/egg/egg-secure-memory.h	Thu Apr  2 03:29:59 2009
@@ -78,6 +78,8 @@
 
 int    egg_secure_check        (const void* p); 
 
+void   egg_secure_validate     (void);
+
 void   egg_secure_dump_blocks  (void);
 
 char*  egg_secure_strdup       (const char *str);



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