Deleted Added
full compact
readelf.c (275666) readelf.c (275698)
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
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.103 2014/05/02 02:25:10 christos Exp $")
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
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 256
64#define MAX_SHNUM 1024
63#define MAX_PHNUM 128
64#define MAX_SHNUM 32768
65#define SIZE_UNKNOWN ((off_t)-1)
65
66private int
67toomany(struct magic_set *ms, const char *name, uint16_t num)
68{
69 if (file_printf(ms, ", too many %s header sections (%u)", name, num
70 ) == -1)
71 return -1;
72 return 0;

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

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

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

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

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

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

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

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

--- 16 unchanged lines hidden ---
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 ---