Contents of /trunk/hal/patches/hal-0.5.10-added-some-more-checks-to-partutil-code.patch
Parent Directory | Revision Log
Revision 597 -
(show annotations)
(download)
Mon May 19 19:05:19 2008 UTC (16 years, 4 months ago) by niro
File size: 2933 byte(s)
Mon May 19 19:05:19 2008 UTC (16 years, 4 months ago) by niro
File size: 2933 byte(s)
-gentoo patches
1 | From e011bd13bdadc04fe269d8564d560c2c591034ff Mon Sep 17 00:00:00 2001 |
2 | From: Danny Kukawka <danny.kukawka@web.de> |
3 | Date: Wed, 28 Nov 2007 19:33:20 +0100 |
4 | Subject: [PATCH] added some more checks to partutil code |
5 | |
6 | Added some more checks to partutil code to prevent possible |
7 | segmentation faults. Check if result of g_slist_nth_data() is |
8 | != NULL before use the returned pointer. |
9 | --- |
10 | partutil/partutil.c | 29 ++++++++++++++++++++++------- |
11 | 1 files changed, 22 insertions(+), 7 deletions(-) |
12 | |
13 | diff --git a/partutil/partutil.c b/partutil/partutil.c |
14 | index b22f9b2..35fc82d 100644 |
15 | --- a/partutil/partutil.c |
16 | +++ b/partutil/partutil.c |
17 | @@ -325,6 +325,9 @@ part_table_free (PartitionTable *p) |
18 | { |
19 | GSList *i; |
20 | |
21 | + if (p == NULL) |
22 | + return; |
23 | + |
24 | for (i = p->entries; i != NULL; i = i->next) { |
25 | PartitionEntry *pe = i->data; |
26 | part_entry_free (pe); |
27 | @@ -914,7 +917,13 @@ part_table_get_size (PartitionTable *p) |
28 | PartitionTable * |
29 | part_table_entry_get_nested (PartitionTable *p, int entry) |
30 | { |
31 | - PartitionEntry *pe = g_slist_nth_data (p->entries, entry); |
32 | + PartitionEntry *pe; |
33 | + |
34 | + if (p == NULL) |
35 | + return NULL; |
36 | + |
37 | + if ((pe = g_slist_nth_data (p->entries, entry)) == NULL) |
38 | + return NULL; |
39 | |
40 | if (pe->is_part_table) |
41 | return pe->part_table; |
42 | @@ -933,7 +942,8 @@ part_table_entry_get_type (PartitionTable *p, int entry) |
43 | if (p == NULL) |
44 | goto out; |
45 | |
46 | - pe = g_slist_nth_data (p->entries, entry); |
47 | + if ((pe = g_slist_nth_data (p->entries, entry)) == NULL) |
48 | + goto out; |
49 | |
50 | switch (p->scheme) { |
51 | case PART_TYPE_GPT: |
52 | @@ -966,7 +976,8 @@ part_table_entry_get_uuid (PartitionTable *p, int entry) |
53 | if (p == NULL) |
54 | goto out; |
55 | |
56 | - pe = g_slist_nth_data (p->entries, entry); |
57 | + if ((pe = g_slist_nth_data (p->entries, entry)) == NULL) |
58 | + goto out; |
59 | |
60 | switch (p->scheme) { |
61 | case PART_TYPE_GPT: |
62 | @@ -991,7 +1002,8 @@ part_table_entry_get_label (PartitionTable *p, int entry) |
63 | if (p == NULL) |
64 | goto out; |
65 | |
66 | - pe = g_slist_nth_data (p->entries, entry); |
67 | + if ((pe = g_slist_nth_data (p->entries, entry)) == NULL) |
68 | + goto out; |
69 | |
70 | switch (p->scheme) { |
71 | case PART_TYPE_GPT: |
72 | @@ -1023,7 +1035,8 @@ part_table_entry_get_flags (PartitionTable *p, int entry) |
73 | if (p == NULL) |
74 | goto out; |
75 | |
76 | - pe = g_slist_nth_data (p->entries, entry); |
77 | + if ((pe = g_slist_nth_data (p->entries, entry)) == NULL) |
78 | + goto out; |
79 | |
80 | ss = g_new0 (char*, 6 + 1); /* hard coded to max items we'll return */ |
81 | ss[0] = NULL; |
82 | @@ -1101,7 +1114,8 @@ part_table_entry_get_offset (PartitionTable *p, int entry) |
83 | if (p == NULL) |
84 | goto out; |
85 | |
86 | - pe = g_slist_nth_data (p->entries, entry); |
87 | + if ((pe = g_slist_nth_data (p->entries, entry)) == NULL) |
88 | + goto out; |
89 | |
90 | switch (p->scheme) { |
91 | case PART_TYPE_GPT: |
92 | @@ -1138,7 +1152,8 @@ part_table_entry_get_size (PartitionTable *p, int entry) |
93 | if (p == NULL) |
94 | goto out; |
95 | |
96 | - pe = g_slist_nth_data (p->entries, entry); |
97 | + if ((pe = g_slist_nth_data (p->entries, entry)) == NULL) |
98 | + goto out; |
99 | |
100 | switch (p->scheme) { |
101 | case PART_TYPE_GPT: |
102 | -- |
103 | 1.5.3.7 |
104 |