Deleted Added
sdiff udiff text old ( 275666 ) new ( 275698 )
full compact
1/*
2 * Copyright (c) Christos Zoulas 2003.
3 * All Rights Reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27#include "file.h"
28
29#ifndef lint
30FILE_RCSID("@(#)$File: readelf.c,v 1.111 2014/12/09 02:47:45 christos Exp $")
31#endif
32
33#ifdef BUILTIN_ELF
34#include <string.h>
35#include <ctype.h>
36#include <stdlib.h>
37#ifdef HAVE_UNISTD_H
38#include <unistd.h>

--- 16 unchanged lines hidden (view full) ---

55#define ELF_ALIGN(a) ((((a) + align - 1) / align) * align)
56
57#define isquote(c) (strchr("'\"`", (c)) != NULL)
58
59private uint16_t getu16(int, uint16_t);
60private uint32_t getu32(int, uint32_t);
61private uint64_t getu64(int, uint64_t);
62
63#define MAX_PHNUM 128
64#define MAX_SHNUM 32768
65#define SIZE_UNKNOWN ((off_t)-1)
66
67private int
68toomany(struct magic_set *ms, const char *name, uint16_t num)
69{
70 if (file_printf(ms, ", too many %s header sections (%u)", name, num
71 ) == -1)
72 return -1;
73 return 0;

--- 246 unchanged lines hidden (view full) ---

320 */
321 for ( ; num; num--) {
322 if (pread(fd, xph_addr, xph_sizeof, off) == -1) {
323 file_badread(ms);
324 return -1;
325 }
326 off += size;
327
328 if (fsize != SIZE_UNKNOWN && xph_offset > fsize) {
329 /* Perhaps warn here */
330 continue;
331 }
332
333 if (xph_type != PT_NOTE)
334 continue;
335
336 /*

--- 623 unchanged lines hidden (view full) ---

960 switch (xsh_type) {
961 case SHT_SYMTAB:
962#if 0
963 case SHT_DYNSYM:
964#endif
965 stripped = 0;
966 break;
967 default:
968 if (fsize != SIZE_UNKNOWN && xsh_offset > fsize) {
969 /* Perhaps warn here */
970 continue;
971 }
972 break;
973 }
974
975 /* Things we can determine when we seek */
976 switch (xsh_type) {

--- 209 unchanged lines hidden (view full) ---

1186 switch (xph_type) {
1187 case PT_DYNAMIC:
1188 linking_style = "dynamically";
1189 break;
1190 case PT_INTERP:
1191 shared_libraries = " (uses shared libs)";
1192 break;
1193 default:
1194 if (fsize != SIZE_UNKNOWN && xph_offset > fsize) {
1195 /* Maybe warn here? */
1196 continue;
1197 }
1198 break;
1199 }
1200
1201 /* Things we can determine when we seek */
1202 switch (xph_type) {
1203 case PT_NOTE:
1204 if (((align = xph_align) & 0x80000000UL) != 0 ||
1205 align < 4) {
1206 if (file_printf(ms,
1207 ", invalid note alignment 0x%lx",
1208 (unsigned long)align) == -1)
1209 return -1;
1210 align = 4;
1211 }
1212 if (sh_num)
1213 break;

--- 66 unchanged lines hidden (view full) ---

1280 */
1281 if((lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
1282 fd = file_pipe2file(ms, fd, buf, nbytes);
1283
1284 if (fstat(fd, &st) == -1) {
1285 file_badread(ms);
1286 return -1;
1287 }
1288 if (S_ISREG(st.st_mode) || st.st_size != 0)
1289 fsize = st.st_size;
1290 else
1291 fsize = SIZE_UNKNOWN;
1292
1293 clazz = buf[EI_CLASS];
1294
1295 switch (clazz) {
1296 case ELFCLASS32:
1297#undef elf_getu
1298#define elf_getu(a, b) elf_getu32(a, b)
1299#undef elfhdr

--- 16 unchanged lines hidden ---