1 2005-02-25 Jakub Jelinek <jakub@redhat.com>
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
10 (get_dynamic_type): Likewise. Increase buff to 64 bytes.
11 (get_elf_section_flags): Increase buff to 33 bytes. Avoid
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.
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
22 get_dynamic_type (unsigned long type)
24 - static char buff[32];
25 + static char buff[64];
29 @@ -1544,7 +1544,7 @@ get_dynamic_type (unsigned long type)
33 - sprintf (buff, _("Processor Specific: %lx"), type);
34 + snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
36 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
38 @@ -1563,10 +1563,11 @@ get_dynamic_type (unsigned long type)
42 - sprintf (buff, _("Operating System specific: %lx"), type);
43 + snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
47 - sprintf (buff, _("<unknown>: %lx"), type);
48 + snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
52 @@ -1587,11 +1588,11 @@ get_file_type (unsigned e_type)
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);
62 - sprintf (buff, _("<unknown>: %x"), e_type);
63 + snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
67 @@ -1698,7 +1699,7 @@ get_machine_name (unsigned e_machine)
69 case EM_XTENSA: return "Tensilica Xtensa Processor";
71 - sprintf (buff, _("<unknown>: %x"), e_machine);
72 + snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_machine);
76 @@ -2206,7 +2207,7 @@ get_osabi_name (unsigned int osabi)
77 case ELFOSABI_STANDALONE: return _("Standalone App");
78 case ELFOSABI_ARM: return "ARM";
80 - sprintf (buff, _("<unknown: %x>"), osabi);
81 + snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
85 @@ -2344,7 +2345,7 @@ get_segment_type (unsigned long p_type)
86 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
89 - sprintf (buff, _("<unknown>: %lx"), p_type);
90 + snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
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);
98 - sprintf (buff, _("<unknown>: %x"), sh_type);
99 + snprintf (buff, sizeof (buff), _("<unknown>: %x"), sh_type);
103 @@ -2926,7 +2927,7 @@ get_elf_class (unsigned int elf_class)
104 case ELFCLASS32: return "ELF32";
105 case ELFCLASS64: return "ELF64";
107 - sprintf (buff, _("<unknown: %x>"), elf_class);
108 + snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
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");
116 - sprintf (buff, _("<unknown: %x>"), encoding);
117 + snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
121 @@ -3621,9 +3622,8 @@ get_64bit_elf_symbols (FILE *file, Elf_I
123 get_elf_section_flags (bfd_vma sh_flags)
125 - static char buff[32];
128 + static char buff[33];
133 @@ -3634,34 +3634,36 @@ get_elf_section_flags (bfd_vma sh_flags)
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;
159 if (flag & SHF_MASKOS)
161 - strcat (buff, "o");
163 sh_flags &= ~ SHF_MASKOS;
165 else if (flag & SHF_MASKPROC)
167 - strcat (buff, "p");
169 sh_flags &= ~ SHF_MASKPROC;
172 - strcat (buff, "x");
183 @@ -3913,7 +3915,7 @@ get_group_flags (unsigned int flags)
187 - sprintf (buff, _("[<unknown>: 0x%x]"), flags);
188 + snprintf (buff, sizeof (buff), _("[<unknown>: 0x%x]"), flags);
192 @@ -5039,9 +5041,9 @@ dynamic_section_mips_val (Elf_Internal_D
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);
205 @@ -5231,13 +5233,11 @@ get_64bit_dynamic_section (FILE *file)
210 -get_dynamic_flags (bfd_vma flags)
212 +print_dynamic_flags (bfd_vma flags)
214 - static char buff[128];
222 @@ -5245,22 +5245,22 @@ get_dynamic_flags (bfd_vma flags)
223 flag = flags & - flags;
231 + putc (' ', stdout);
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;
249 - p = strchr (p, '\0');
255 /* Parse and display the contents of the dynamic section. */
256 @@ -5457,7 +5457,7 @@ process_dynamic_section (FILE *file)
260 - puts (get_dynamic_flags (entry->d_un.d_val));
261 + print_dynamic_flags (entry->d_un.d_val);
265 @@ -6266,11 +6266,12 @@ get_symbol_binding (unsigned int binding
266 case STB_WEAK: return "WEAK";
268 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
269 - sprintf (buff, _("<processor specific>: %d"), binding);
270 + snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
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);
276 - sprintf (buff, _("<unknown>: %d"), binding);
277 + snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
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";
285 - sprintf (buff, _("<processor specific>: %d"), type);
286 + snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
288 else if (type >= STT_LOOS && type <= STT_HIOS)
290 @@ -6313,10 +6314,10 @@ get_symbol_type (unsigned int type)
294 - sprintf (buff, _("<OS specific>: %d"), type);
295 + snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
298 - sprintf (buff, _("<unknown>: %d"), type);
299 + snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
303 @@ -7642,7 +7643,7 @@ get_TAG_name (unsigned long tag)
305 static char buffer[100];
307 - sprintf (buffer, _("Unknown TAG value: %lx"), tag);
308 + snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
312 @@ -7755,7 +7756,7 @@ get_AT_name (unsigned long attribute)
314 static char buffer[100];
316 - sprintf (buffer, _("Unknown AT value: %lx"), attribute);
317 + snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), attribute);
321 @@ -7791,7 +7792,7 @@ get_FORM_name (unsigned long form)
323 static char buffer[100];
325 - sprintf (buffer, _("Unknown FORM value: %lx"), form);
326 + snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
330 @@ -10606,9 +10607,10 @@ process_mips_specific (FILE *file)
331 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
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);
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);
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);
356 printf ("%3lu: ", (unsigned long) cnt);
358 @@ -11050,7 +11053,7 @@ get_note_type (unsigned e_type)
362 - sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
363 + snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
367 @@ -11072,7 +11075,7 @@ get_netbsd_elfcore_note_type (unsigned e
369 if (e_type < NT_NETBSDCORE_FIRSTMACH)
371 - sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
372 + snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
376 @@ -11111,7 +11114,8 @@ get_netbsd_elfcore_note_type (unsigned e
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);