[PATCH] libpartutil: dereference pointer after checking it's not NULL

Guillem Jover guillem.jover at nokia.com
Thu Nov 8 19:27:14 PST 2007


---
 partutil/partutil.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/partutil/partutil.c b/partutil/partutil.c
index 36078c0..b22f9b2 100644
--- a/partutil/partutil.c
+++ b/partutil/partutil.c
@@ -928,11 +928,13 @@ char *
 part_table_entry_get_type (PartitionTable *p, int entry)
 {
 	char *s = NULL;
-	PartitionEntry *pe = g_slist_nth_data (p->entries, entry);
+	PartitionEntry *pe;
 
 	if (p == NULL)
 		goto out;
 
+	pe = g_slist_nth_data (p->entries, entry);
+
 	switch (p->scheme) {
 	case PART_TYPE_GPT:
 		s = get_le_guid (&(pe->data[0]));
@@ -959,11 +961,13 @@ char *
 part_table_entry_get_uuid (PartitionTable *p, int entry)
 {
 	char *s = NULL;
-	PartitionEntry *pe = g_slist_nth_data (p->entries, entry);
+	PartitionEntry *pe;
 
 	if (p == NULL)
 		goto out;
 
+	pe = g_slist_nth_data (p->entries, entry);
+
 	switch (p->scheme) {
 	case PART_TYPE_GPT:
 		s = get_le_guid (&(pe->data[16]));
@@ -982,11 +986,13 @@ char *
 part_table_entry_get_label (PartitionTable *p, int entry)
 {
 	char *s = NULL;
-	PartitionEntry *pe = g_slist_nth_data (p->entries, entry);
+	PartitionEntry *pe;
 
 	if (p == NULL)
 		goto out;
 
+	pe = g_slist_nth_data (p->entries, entry);
+
 	switch (p->scheme) {
 	case PART_TYPE_GPT:
 		s = g_utf16_to_utf8 ((const gunichar2 *) &(pe->data[56]), 36, NULL, NULL, NULL);
@@ -1012,11 +1018,13 @@ part_table_entry_get_flags (PartitionTable *p, int entry)
 	char **ss = NULL;
 	guint32 apm_status;
 	guint64 gpt_attributes;
-	PartitionEntry *pe = g_slist_nth_data (p->entries, entry);
+	PartitionEntry *pe;
 
 	if (p == NULL)
 		goto out;
 
+	pe = g_slist_nth_data (p->entries, entry);
+
 	ss = g_new0 (char*, 6 + 1); /* hard coded to max items we'll return */
 	ss[0] = NULL;
 	n = 0;
@@ -1087,12 +1095,14 @@ guint64
 part_table_entry_get_offset (PartitionTable *p, int entry)
 {
 	guint64 val;
-	PartitionEntry *pe = g_slist_nth_data (p->entries, entry);
+	PartitionEntry *pe;
 
 	val = G_MAXUINT64;
 	if (p == NULL)
 		goto out;
 
+	pe = g_slist_nth_data (p->entries, entry);
+
 	switch (p->scheme) {
 	case PART_TYPE_GPT:
 		val = 0x200 * ((guint64) get_le64 (pe->data + 32));
@@ -1122,12 +1132,14 @@ guint64
 part_table_entry_get_size (PartitionTable *p, int entry)
 {
 	guint64 val;
-	PartitionEntry *pe = g_slist_nth_data (p->entries, entry);
+	PartitionEntry *pe;
 
 	val = G_MAXUINT64;
 	if (p == NULL)
 		goto out;
 
+	pe = g_slist_nth_data (p->entries, entry);
+
 	switch (p->scheme) {
 	case PART_TYPE_GPT:
 		val = 0x200 * (((guint64) get_le64 (pe->data + 40)) - ((guint64) get_le64 (pe->data + 32)) + 1);
-- 
1.5.3.5



More information about the hal mailing list