~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to util/grub-pe2elf.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2011-05-17 23:59:10 UTC
  • mto: (17.3.55 sid)
  • mto: This revision was merged to the branch mainline in revision 122.
  • Revision ID: james.westby@ubuntu.com-20110517235910-ma8u889vyjdfro27
Tags: upstream-1.99
ImportĀ upstreamĀ versionĀ 1.99

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
#define BSS_SECTION     4
80
80
#define MODNAME_SECTION 5
81
81
#define MODDEPS_SECTION 6
82
 
#define SYMTAB_SECTION  7
83
 
#define STRTAB_SECTION  8
 
82
#define MODLICENSE_SECTION      7
 
83
#define SYMTAB_SECTION  8
 
84
#define STRTAB_SECTION  9
84
85
 
85
 
#define REL_SECTION     9
86
 
#define MAX_SECTIONS    12
 
86
#define REL_SECTION     10
 
87
#define MAX_SECTIONS    16
87
88
 
88
89
#define STRTAB_BLOCK    256
89
90
 
96
97
grub_uint32_t offset;
97
98
 
98
99
static int
99
 
insert_string (char *name)
 
100
insert_string (const char *name)
100
101
{
101
102
  int len, result;
102
103
 
124
125
{
125
126
  int *section_map;
126
127
  int i;
 
128
  char *pe_strtab = (image + pe_chdr->symtab_offset
 
129
                     + pe_chdr->num_symbols * sizeof (struct grub_pe32_symbol));
127
130
 
128
131
  section_map = xmalloc ((pe_chdr->num_sections + 1) * sizeof (int));
129
132
  section_map[0] = 0;
131
134
  for (i = 0; i < pe_chdr->num_sections; i++, pe_shdr++)
132
135
    {
133
136
      grub_uint32_t idx;
134
 
 
135
 
      if (! strcmp (pe_shdr->name, ".text"))
 
137
      const char *name = pe_shdr->name;
 
138
 
 
139
      if (name[0] == '/' && isdigit (name[1]))
 
140
      {
 
141
        char t[sizeof (pe_shdr->name) + 1];
 
142
        memcpy (t, name, sizeof (pe_shdr->name));
 
143
        t[sizeof (pe_shdr->name)] = 0;
 
144
        name = pe_strtab + atoi (t + 1);
 
145
      }
 
146
 
 
147
      if (! strcmp (name, ".text"))
136
148
        {
137
149
          idx = TEXT_SECTION;
138
150
          shdr[idx].sh_flags = SHF_ALLOC | SHF_EXECINSTR;
139
151
        }
140
 
      else if (! strcmp (pe_shdr->name, ".rdata"))
 
152
      else if (! strcmp (name, ".rdata"))
141
153
        {
142
154
          idx = RDATA_SECTION;
143
155
          shdr[idx].sh_flags = SHF_ALLOC;
144
156
        }
145
 
      else if (! strcmp (pe_shdr->name, ".data"))
 
157
      else if (! strcmp (name, ".data"))
146
158
        {
147
159
          idx = DATA_SECTION;
148
160
          shdr[idx].sh_flags = SHF_ALLOC | SHF_WRITE;
149
161
        }
150
 
      else if (! strcmp (pe_shdr->name, ".bss"))
 
162
      else if (! strcmp (name, ".bss"))
151
163
        {
152
164
          idx = BSS_SECTION;
153
165
          shdr[idx].sh_flags = SHF_ALLOC | SHF_WRITE;
154
166
        }
155
 
      else if (! strcmp (pe_shdr->name, ".modname"))
 
167
      else if (! strcmp (name, ".modname"))
156
168
        idx = MODNAME_SECTION;
157
 
      else if (! strcmp (pe_shdr->name, ".moddeps"))
 
169
      else if (! strcmp (name, ".moddeps"))
158
170
        idx = MODDEPS_SECTION;
 
171
      else if (strcmp (name, ".module_license") == 0)
 
172
        idx = MODLICENSE_SECTION;
159
173
      else
160
174
        {
161
175
          section_map[i + 1] = -1;
181
195
 
182
196
      if (pe_shdr->relocations_offset)
183
197
        {
184
 
          char name[5 + strlen (pe_shdr->name)];
 
198
          char relname[5 + strlen (name)];
185
199
 
186
200
          if (num_sections >= MAX_SECTIONS)
187
201
            grub_util_error ("too many sections");
188
202
 
189
 
          sprintf (name, ".rel%s", pe_shdr->name);
 
203
          sprintf (relname, ".rel%s", name);
190
204
 
191
 
          shdr[num_sections].sh_name = insert_string (name);
 
205
          shdr[num_sections].sh_name = insert_string (relname);
192
206
          shdr[num_sections].sh_link = i;
193
207
          shdr[num_sections].sh_info = idx;
194
208
 
197
211
          num_sections++;
198
212
        }
199
213
      else
200
 
        shdr[idx].sh_name = insert_string (pe_shdr->name);
 
214
        shdr[idx].sh_name = insert_string (name);
201
215
    }
202
216
 
203
217
  return section_map;