]> git.pld-linux.org Git - packages/binutils.git/blame - binutils-readelf-overflows.patch
This commit was manufactured by cvs2git to create branch 'AC-branch'.
[packages/binutils.git] / binutils-readelf-overflows.patch
CommitLineData
52cb69e7
AM
12005-02-25 Jakub Jelinek <jakub@redhat.com>
2
3 * readelf.c (get_file_type, get_machine_name, get_osabi_name,
4 get_segment_type, get_section_type_name, get_elf_class,
5 get_data_encoding, get_group_flags, dynamic_section_mips_val,
6 get_symbol_binding, get_symbol_type, get_TAG_name, get_FORM_name,
7 get_AT_name, process_mips_specific, process_gnu_liblist,
8 get_note_type, get_netbsd_elfcore_note_type): Use snprintf instead of
9 sprintf where needed.
10 (get_dynamic_type): Likewise. Increase buff to 64 bytes.
11 (get_elf_section_flags): Increase buff to 33 bytes. Avoid
12 using strcat.
13 (get_dynamic_flags): Renamed to...
14 (print_dynamic_flags): ... this. Print the flags to stdout instead
15 of returning them as string.
16 (process_dynamic_section): Adjust caller.
17
18--- binutils/readelf.c.jj 2004-12-20 14:16:49.000000000 -0500
19+++ binutils/readelf.c 2005-02-28 03:43:06.000000000 -0500
20@@ -1440,7 +1440,7 @@ get_ia64_dynamic_type (unsigned long typ
21 static const char *
22 get_dynamic_type (unsigned long type)
23 {
24- static char buff[32];
25+ static char buff[64];
26
27 switch (type)
28 {
29@@ -1544,7 +1544,7 @@ get_dynamic_type (unsigned long type)
30 if (result != NULL)
31 return result;
32
33- sprintf (buff, _("Processor Specific: %lx"), type);
34+ snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
35 }
36 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
37 {
38@@ -1563,10 +1563,11 @@ get_dynamic_type (unsigned long type)
39 if (result != NULL)
40 return result;
41
42- sprintf (buff, _("Operating System specific: %lx"), type);
43+ snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
44+ type);
45 }
46 else
47- sprintf (buff, _("<unknown>: %lx"), type);
48+ snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
49
50 return buff;
51 }
52@@ -1587,11 +1588,11 @@ get_file_type (unsigned e_type)
53
54 default:
55 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
56- sprintf (buff, _("Processor Specific: (%x)"), e_type);
57+ snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
58 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
59- sprintf (buff, _("OS Specific: (%x)"), e_type);
60+ snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
61 else
62- sprintf (buff, _("<unknown>: %x"), e_type);
63+ snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
64 return buff;
65 }
66 }
67@@ -1698,7 +1699,7 @@ get_machine_name (unsigned e_machine)
68 case EM_XTENSA_OLD:
69 case EM_XTENSA: return "Tensilica Xtensa Processor";
70 default:
71- sprintf (buff, _("<unknown>: %x"), e_machine);
72+ snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_machine);
73 return buff;
74 }
75 }
76@@ -2206,7 +2207,7 @@ get_osabi_name (unsigned int osabi)
77 case ELFOSABI_STANDALONE: return _("Standalone App");
78 case ELFOSABI_ARM: return "ARM";
79 default:
80- sprintf (buff, _("<unknown: %x>"), osabi);
81+ snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
82 return buff;
83 }
84 }
85@@ -2344,7 +2345,7 @@ get_segment_type (unsigned long p_type)
86 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
87 }
88 else
89- sprintf (buff, _("<unknown>: %lx"), p_type);
90+ snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
91
92 return buff;
93 }
94@@ -2528,7 +2529,7 @@ get_section_type_name (unsigned int sh_t
95 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
96 sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
97 else
98- sprintf (buff, _("<unknown>: %x"), sh_type);
99+ snprintf (buff, sizeof (buff), _("<unknown>: %x"), sh_type);
100
101 return buff;
102 }
103@@ -2926,7 +2927,7 @@ get_elf_class (unsigned int elf_class)
104 case ELFCLASS32: return "ELF32";
105 case ELFCLASS64: return "ELF64";
106 default:
107- sprintf (buff, _("<unknown: %x>"), elf_class);
108+ snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
109 return buff;
110 }
111 }
112@@ -2942,7 +2943,7 @@ get_data_encoding (unsigned int encoding
113 case ELFDATA2LSB: return _("2's complement, little endian");
114 case ELFDATA2MSB: return _("2's complement, big endian");
115 default:
116- sprintf (buff, _("<unknown: %x>"), encoding);
117+ snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
118 return buff;
119 }
120 }
121@@ -3621,9 +3622,8 @@ get_64bit_elf_symbols (FILE *file, Elf_I
122 static const char *
123 get_elf_section_flags (bfd_vma sh_flags)
124 {
125- static char buff[32];
126-
127- *buff = 0;
128+ static char buff[33];
129+ char *p = buff;
130
131 while (sh_flags)
132 {
133@@ -3634,34 +3634,36 @@ get_elf_section_flags (bfd_vma sh_flags)
134
135 switch (flag)
136 {
137- case SHF_WRITE: strcat (buff, "W"); break;
138- case SHF_ALLOC: strcat (buff, "A"); break;
139- case SHF_EXECINSTR: strcat (buff, "X"); break;
140- case SHF_MERGE: strcat (buff, "M"); break;
141- case SHF_STRINGS: strcat (buff, "S"); break;
142- case SHF_INFO_LINK: strcat (buff, "I"); break;
143- case SHF_LINK_ORDER: strcat (buff, "L"); break;
144- case SHF_OS_NONCONFORMING: strcat (buff, "O"); break;
145- case SHF_GROUP: strcat (buff, "G"); break;
146- case SHF_TLS: strcat (buff, "T"); break;
147+ case SHF_WRITE: *p = 'W'; break;
148+ case SHF_ALLOC: *p = 'A'; break;
149+ case SHF_EXECINSTR: *p = 'X'; break;
150+ case SHF_MERGE: *p = 'M'; break;
151+ case SHF_STRINGS: *p = 'S'; break;
152+ case SHF_INFO_LINK: *p = 'I'; break;
153+ case SHF_LINK_ORDER: *p = 'L'; break;
154+ case SHF_OS_NONCONFORMING: *p = 'O'; break;
155+ case SHF_GROUP: *p = 'G'; break;
156+ case SHF_TLS: *p = 'T'; break;
157
158 default:
159 if (flag & SHF_MASKOS)
160 {
161- strcat (buff, "o");
162+ *p = 'o';
163 sh_flags &= ~ SHF_MASKOS;
164 }
165 else if (flag & SHF_MASKPROC)
166 {
167- strcat (buff, "p");
168+ *p = 'p';
169 sh_flags &= ~ SHF_MASKPROC;
170 }
171 else
172- strcat (buff, "x");
173+ *p = 'x';
174 break;
175 }
176+ p++;
177 }
178
179+ *p = '\0';
180 return buff;
181 }
182
183@@ -3913,7 +3915,7 @@ get_group_flags (unsigned int flags)
184 return "COMDAT";
185
186 default:
187- sprintf (buff, _("[<unknown>: 0x%x]"), flags);
188+ snprintf (buff, sizeof (buff), _("[<unknown>: 0x%x]"), flags);
189 break;
190 }
191 return buff;
192@@ -5039,9 +5041,9 @@ dynamic_section_mips_val (Elf_Internal_D
193
194 time_t time = entry->d_un.d_val;
195 tmp = gmtime (&time);
196- sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
197- tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
198- tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
199+ snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
200+ tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
201+ tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
202 printf ("Time Stamp: %s\n", timebuf);
203 }
204 break;
205@@ -5231,13 +5233,11 @@ get_64bit_dynamic_section (FILE *file)
206 return 1;
207 }
208
209-static const char *
210-get_dynamic_flags (bfd_vma flags)
211+static void
212+print_dynamic_flags (bfd_vma flags)
213 {
214- static char buff[128];
215- char *p = buff;
216+ int first = 1;
217
218- *p = '\0';
219 while (flags)
220 {
221 bfd_vma flag;
222@@ -5245,22 +5245,22 @@ get_dynamic_flags (bfd_vma flags)
223 flag = flags & - flags;
224 flags &= ~ flag;
225
226- if (p != buff)
227- *p++ = ' ';
228+ if (first)
229+ first = 0;
230+ else
231+ putc (' ', stdout);
232
233 switch (flag)
234 {
235- case DF_ORIGIN: strcpy (p, "ORIGIN"); break;
236- case DF_SYMBOLIC: strcpy (p, "SYMBOLIC"); break;
237- case DF_TEXTREL: strcpy (p, "TEXTREL"); break;
238- case DF_BIND_NOW: strcpy (p, "BIND_NOW"); break;
239- case DF_STATIC_TLS: strcpy (p, "STATIC_TLS"); break;
240- default: strcpy (p, "unknown"); break;
241+ case DF_ORIGIN: fputs ("ORIGIN", stdout); break;
242+ case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break;
243+ case DF_TEXTREL: fputs ("TEXTREL", stdout); break;
244+ case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break;
245+ case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break;
246+ default: fputs ("unknown", stdout); break;
247 }
248-
249- p = strchr (p, '\0');
250 }
251- return buff;
252+ puts ("");
253 }
254
255 /* Parse and display the contents of the dynamic section. */
256@@ -5457,7 +5457,7 @@ process_dynamic_section (FILE *file)
257 {
258 case DT_FLAGS:
259 if (do_dynamic)
260- puts (get_dynamic_flags (entry->d_un.d_val));
261+ print_dynamic_flags (entry->d_un.d_val);
262 break;
263
264 case DT_AUXILIARY:
265@@ -6266,11 +6266,12 @@ get_symbol_binding (unsigned int binding
266 case STB_WEAK: return "WEAK";
267 default:
268 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
269- sprintf (buff, _("<processor specific>: %d"), binding);
270+ snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
271+ binding);
272 else if (binding >= STB_LOOS && binding <= STB_HIOS)
273- sprintf (buff, _("<OS specific>: %d"), binding);
274+ snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
275 else
276- sprintf (buff, _("<unknown>: %d"), binding);
277+ snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
278 return buff;
279 }
280 }
281@@ -6301,7 +6302,7 @@ get_symbol_type (unsigned int type)
282 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
283 return "PARISC_MILLI";
284
285- sprintf (buff, _("<processor specific>: %d"), type);
286+ snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
287 }
288 else if (type >= STT_LOOS && type <= STT_HIOS)
289 {
290@@ -6313,10 +6314,10 @@ get_symbol_type (unsigned int type)
291 return "HP_STUB";
292 }
293
294- sprintf (buff, _("<OS specific>: %d"), type);
295+ snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
296 }
297 else
298- sprintf (buff, _("<unknown>: %d"), type);
299+ snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
300 return buff;
301 }
302 }
303@@ -7642,7 +7643,7 @@ get_TAG_name (unsigned long tag)
304 {
305 static char buffer[100];
306
307- sprintf (buffer, _("Unknown TAG value: %lx"), tag);
308+ snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
309 return buffer;
310 }
311 }
312@@ -7755,7 +7756,7 @@ get_AT_name (unsigned long attribute)
313 {
314 static char buffer[100];
315
316- sprintf (buffer, _("Unknown AT value: %lx"), attribute);
317+ snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), attribute);
318 return buffer;
319 }
320 }
321@@ -7791,7 +7792,7 @@ get_FORM_name (unsigned long form)
322 {
323 static char buffer[100];
324
325- sprintf (buffer, _("Unknown FORM value: %lx"), form);
326+ snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
327 return buffer;
328 }
329 }
330@@ -10606,9 +10607,10 @@ process_mips_specific (FILE *file)
331 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
332
333 tmp = gmtime (&time);
334- sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
335- tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
336- tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
337+ snprintf (timebuf, sizeof (timebuf),
338+ "%04u-%02u-%02uT%02u:%02u:%02u",
339+ tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
340+ tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
341
342 printf ("%3lu: ", (unsigned long) cnt);
343 if (VALID_DYNAMIC_NAME (liblist.l_name))
344@@ -10984,9 +10986,10 @@ process_gnu_liblist (FILE *file)
345 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
346
347 tmp = gmtime (&time);
348- sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
349- tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
350- tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
351+ snprintf (timebuf, sizeof (timebuf),
352+ "%04u-%02u-%02uT%02u:%02u:%02u",
353+ tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
354+ tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
355
356 printf ("%3lu: ", (unsigned long) cnt);
357 if (do_wide)
358@@ -11050,7 +11053,7 @@ get_note_type (unsigned e_type)
359 break;
360 }
361
362- sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
363+ snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
364 return buff;
365 }
366
367@@ -11072,7 +11075,7 @@ get_netbsd_elfcore_note_type (unsigned e
368
369 if (e_type < NT_NETBSDCORE_FIRSTMACH)
370 {
371- sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
372+ snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
373 return buff;
374 }
375
376@@ -11111,7 +11114,8 @@ get_netbsd_elfcore_note_type (unsigned e
377 }
378 }
379
380- sprintf (buff, _("PT_FIRSTMACH+%d"), e_type - NT_NETBSDCORE_FIRSTMACH);
381+ snprintf (buff, sizeof (buff), _("PT_FIRSTMACH+%d"),
382+ e_type - NT_NETBSDCORE_FIRSTMACH);
383 return buff;
384 }
385
This page took 0.115089 seconds and 4 git commands to generate.