[pacman-dev] [PATCH] Fixed some small but critical bugs

Sivert Berg sivertb at stud.ntnu.no
Tue Dec 16 14:04:32 EST 2008


The not so well tested freeing code turned out to have a few subtle yet
very dangerous bugs. They should now be sorted out, preventing the
database from going corrupt everytime you reuse an old inode.

Signed-off-by: Sivert Berg <sivertb at stud.ntnu.no>
---
 lib/libalpm/be_packed.h |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/libalpm/be_packed.h b/lib/libalpm/be_packed.h
index e118a3a..b2654c7 100644
--- a/lib/libalpm/be_packed.h
+++ b/lib/libalpm/be_packed.h
@@ -195,7 +195,7 @@ int _pack_bitmap_free(group_desc_t *group, int n)
 	int i = n / 32;
 	int j = n % 32;
 
-	group->bitmap[i] &= ~(i << j);
+	group->bitmap[i] &= ~(1 << j);
 	return 0;
 }
 
@@ -217,7 +217,7 @@ int _pack_get_free_block(pack_db_t *db)
 			group->blocks_free--;
 			ret = _pack_check_bitmap(group);
 			ret += i * BLOCKS_PER_GROUP;
-			return ret;;
+			return ret;
 		}
 	}
 
@@ -238,7 +238,7 @@ int _pack_block_free(pack_db_t *db, int block)
 	int g, b;
 
 	g = block / BLOCKS_PER_GROUP;
-	b = block & BLOCKS_PER_GROUP;
+	b = block % BLOCKS_PER_GROUP;
 
 	group = _pack_get_group(db, g);
   group->blocks_free++;
@@ -299,6 +299,7 @@ int _pack_inode_free(pack_db_t *db, int in)
 
 	block = inode->block[6];
 	blocks = _pack_get_block(db, block);
+	inode->block[6] = -1;
 
 	while(blocks != NULL) {
 		for (i = 0; i < size; i++) {
@@ -526,9 +527,8 @@ int _pack_file_puts(pack_db_t *db, pack_file_t *file,
 {
 	size_t i;
 	size_t b_pos = file->pos % BLOCK_SIZE;
-	char *dest = _pack_get_block(db,
-			_pack_inode_add_block(db, file->inode, file->pos / BLOCK_SIZE));
-	int block;
+	int block = _pack_inode_add_block(db, file->inode, file->pos / BLOCK_SIZE);
+	char *dest = _pack_get_block(db, block);
 
 	for (i = 0; i < size; i++, file->pos++, b_pos++)
 	{
-- 
1.6.0.5



More information about the pacman-dev mailing list