diff options
author | stefw <stefw@localhost> | 2009-04-02 03:29:59 +0000 |
---|---|---|
committer | stefw <stefw@localhost> | 2009-04-02 03:29:59 +0000 |
commit | 3006b0e48c276cecc32728f5ebfa525959a9078e (patch) | |
tree | d6397c7935e7683063ec4c5bca142a54d2617414 | |
parent | 2e8352d203eceebb2b44917b6ddcfc1e26a52002 (diff) | |
download | gnome-keyring-3006b0e48c276cecc32728f5ebfa525959a9078e.tar.gz |
Add validator which walks the secure memory heap and checks for inconsistencies.
svn path=/trunk/; revision=1707
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | egg/egg-secure-memory.c | 59 | ||||
-rw-r--r-- | egg/egg-secure-memory.h | 2 |
3 files changed, 64 insertions, 1 deletions
@@ -2,6 +2,10 @@ * egg/egg-secure-memory.c: Fix assertion that occurs when shrinking block of secure memory and then expanding again. + + * egg/egg-secure-memory.c: + * egg/egg-secure-memory.h: Add validator which walks the + secure memory heap and checks for inconsistencies. 2009-03-20 Stef Walter <stef@memberwebs.com> diff --git a/egg/egg-secure-memory.c b/egg/egg-secure-memory.c index 2d584efc..a2153645 100644 --- a/egg/egg-secure-memory.c +++ b/egg/egg-secure-memory.c @@ -350,6 +350,8 @@ sec_insert_cell_ring (Cell **ring, Cell *cell) } *ring = cell; + ASSERT (cell->next->prev == cell); + ASSERT (cell->prev->next == cell); } static void @@ -359,7 +361,10 @@ sec_remove_cell_ring (Cell **ring, Cell *cell) 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 @@ sec_allocated (Block *block, void *memory) 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 @@ egg_secure_check (const void *memory) } 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; diff --git a/egg/egg-secure-memory.h b/egg/egg-secure-memory.h index 00ff333c..f824a4f4 100644 --- a/egg/egg-secure-memory.h +++ b/egg/egg-secure-memory.h @@ -78,6 +78,8 @@ void egg_secure_free_full (void* p, int fallback); 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); |