/[gentoo-projects]/pax-utils/scanelf.c
Gentoo

Diff of /pax-utils/scanelf.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.183 Revision 1.185
1/* 1/*
2 * Copyright 2003-2007 Gentoo Foundation 2 * Copyright 2003-2007 Gentoo Foundation
3 * Distributed under the terms of the GNU General Public License v2 3 * Distributed under the terms of the GNU General Public License v2
4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.183 2007/06/29 19:49:26 solar Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.185 2007/08/18 04:59:32 vapier Exp $
5 * 5 *
6 * Copyright 2003-2007 Ned Ludd - <solar@gentoo.org> 6 * Copyright 2003-2007 Ned Ludd - <solar@gentoo.org>
7 * Copyright 2004-2007 Mike Frysinger - <vapier@gentoo.org> 7 * Copyright 2004-2007 Mike Frysinger - <vapier@gentoo.org>
8 */ 8 */
9 9
10#include "paxinc.h" 10#include "paxinc.h"
11 11
12static const char *rcsid = "$Id: scanelf.c,v 1.183 2007/06/29 19:49:26 solar Exp $"; 12static const char *rcsid = "$Id: scanelf.c,v 1.185 2007/08/18 04:59:32 vapier Exp $";
13#define argv0 "scanelf" 13#define argv0 "scanelf"
14 14
15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+') 15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+')
16 16
17/* prototypes */ 17/* prototypes */
356 Elf ## B ## _Dyn *dyn; \ 356 Elf ## B ## _Dyn *dyn; \
357 Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ 357 Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \
358 Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \ 358 Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \
359 Elf ## B ## _Off offset; \ 359 Elf ## B ## _Off offset; \
360 for (i = 0; i < EGET(ehdr->e_phnum); i++) { \ 360 for (i = 0; i < EGET(ehdr->e_phnum); i++) { \
361 if (EGET(phdr[i].p_type) != PT_DYNAMIC) continue; \ 361 if (EGET(phdr[i].p_type) != PT_DYNAMIC || EGET(phdr[i].p_filesz) == 0) continue; \
362 offset = EGET(phdr[i].p_offset); \ 362 offset = EGET(phdr[i].p_offset); \
363 if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) continue; \ 363 if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) continue; \
364 dyn = DYN ## B (elf->data + offset); \ 364 dyn = DYN ## B (elf->data + offset); \
365 while (EGET(dyn->d_tag) != DT_NULL) { \ 365 while (EGET(dyn->d_tag) != DT_NULL) { \
366 if (EGET(dyn->d_tag) == DT_TEXTREL) { /*dyn->d_tag != DT_FLAGS)*/ \ 366 if (EGET(dyn->d_tag) == DT_TEXTREL) { /*dyn->d_tag != DT_FLAGS)*/ \
558 Elf ## B ## _Off offset; \ 558 Elf ## B ## _Off offset; \
559 Elf ## B ## _Xword word; \ 559 Elf ## B ## _Xword word; \
560 /* Scan all the program headers */ \ 560 /* Scan all the program headers */ \
561 for (i = 0; i < EGET(ehdr->e_phnum); i++) { \ 561 for (i = 0; i < EGET(ehdr->e_phnum); i++) { \
562 /* Just scan dynamic headers */ \ 562 /* Just scan dynamic headers */ \
563 if (EGET(phdr[i].p_type) != PT_DYNAMIC) continue; \ 563 if (EGET(phdr[i].p_type) != PT_DYNAMIC || EGET(phdr[i].p_filesz) == 0) continue; \
564 offset = EGET(phdr[i].p_offset); \ 564 offset = EGET(phdr[i].p_offset); \
565 if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) continue; \ 565 if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) continue; \
566 /* Just scan dynamic RPATH/RUNPATH headers */ \ 566 /* Just scan dynamic RPATH/RUNPATH headers */ \
567 dyn = DYN ## B (elf->data + offset); \ 567 dyn = DYN ## B (elf->data + offset); \
568 while ((word=EGET(dyn->d_tag)) != DT_NULL) { \ 568 while ((word=EGET(dyn->d_tag)) != DT_NULL) { \
818 Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ 818 Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \
819 Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \ 819 Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \
820 Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \ 820 Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \
821 Elf ## B ## _Off offset; \ 821 Elf ## B ## _Off offset; \
822 for (i = 0; i < EGET(ehdr->e_phnum); i++) { \ 822 for (i = 0; i < EGET(ehdr->e_phnum); i++) { \
823 if (EGET(phdr[i].p_type) != PT_DYNAMIC) continue; \ 823 if (EGET(phdr[i].p_type) != PT_DYNAMIC || EGET(phdr[i].p_filesz) == 0) continue; \
824 offset = EGET(phdr[i].p_offset); \ 824 offset = EGET(phdr[i].p_offset); \
825 if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) continue; \ 825 if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) continue; \
826 dyn = DYN ## B (elf->data + offset); \ 826 dyn = DYN ## B (elf->data + offset); \
827 while (EGET(dyn->d_tag) != DT_NULL) { \ 827 while (EGET(dyn->d_tag) != DT_NULL) { \
828 if (EGET(dyn->d_tag) == DT_NEEDED) { \ 828 if (EGET(dyn->d_tag) == DT_NEEDED) { \
893 Elf ## B ## _Dyn *dyn; \ 893 Elf ## B ## _Dyn *dyn; \
894 Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ 894 Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \
895 Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \ 895 Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \
896 Elf ## B ## _Off offset; \ 896 Elf ## B ## _Off offset; \
897 for (i = 0; i < EGET(ehdr->e_phnum); i++) { \ 897 for (i = 0; i < EGET(ehdr->e_phnum); i++) { \
898 if (EGET(phdr[i].p_type) != PT_DYNAMIC) continue; \ 898 if (EGET(phdr[i].p_type) != PT_DYNAMIC || EGET(phdr[i].p_filesz) == 0) continue; \
899 dynamic = 1; \ 899 dynamic = 1; \
900 offset = EGET(phdr[i].p_offset); \ 900 offset = EGET(phdr[i].p_offset); \
901 if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) continue; \ 901 if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) continue; \
902 dyn = DYN ## B (elf->data + offset); \ 902 dyn = DYN ## B (elf->data + offset); \
903 while (EGET(dyn->d_tag) != DT_NULL) { \ 903 while (EGET(dyn->d_tag) != DT_NULL) { \
945 Elf ## B ## _Off offset; \ 945 Elf ## B ## _Off offset; \
946 /* only look for soname in shared objects */ \ 946 /* only look for soname in shared objects */ \
947 if (ehdr->e_type != ET_DYN) \ 947 if (ehdr->e_type != ET_DYN) \
948 return NULL; \ 948 return NULL; \
949 for (i = 0; i < EGET(ehdr->e_phnum); i++) { \ 949 for (i = 0; i < EGET(ehdr->e_phnum); i++) { \
950 if (EGET(phdr[i].p_type) != PT_DYNAMIC) continue; \ 950 if (EGET(phdr[i].p_type) != PT_DYNAMIC || EGET(phdr[i].p_filesz) == 0) continue; \
951 offset = EGET(phdr[i].p_offset); \ 951 offset = EGET(phdr[i].p_offset); \
952 if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) continue; \ 952 if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) continue; \
953 dyn = DYN ## B (elf->data + offset); \ 953 dyn = DYN ## B (elf->data + offset); \
954 while (EGET(dyn->d_tag) != DT_NULL) { \ 954 while (EGET(dyn->d_tag) != DT_NULL) { \
955 if (EGET(dyn->d_tag) == DT_SONAME) { \ 955 if (EGET(dyn->d_tag) == DT_SONAME) { \
1546} 1546}
1547 1547
1548#endif 1548#endif
1549 1549
1550/* scan /etc/ld.so.conf for paths */ 1550/* scan /etc/ld.so.conf for paths */
1551static void scanelf_ldpath() 1551static void scanelf_ldpath(void)
1552{ 1552{
1553 char scan_l, scan_ul, scan_ull; 1553 char scan_l, scan_ul, scan_ull;
1554 int i = 0; 1554 int i = 0;
1555 1555
1556 if (!ldpaths[0]) 1556 if (!ldpaths[0])
1570 if (!scan_ul) scanelf_dir("/usr/lib"); 1570 if (!scan_ul) scanelf_dir("/usr/lib");
1571 if (!scan_ull) scanelf_dir("/usr/local/lib"); 1571 if (!scan_ull) scanelf_dir("/usr/local/lib");
1572} 1572}
1573 1573
1574/* scan env PATH for paths */ 1574/* scan env PATH for paths */
1575static void scanelf_envpath() 1575static void scanelf_envpath(void)
1576{ 1576{
1577 char *path, *p; 1577 char *path, *p;
1578 1578
1579 path = getenv("PATH"); 1579 path = getenv("PATH");
1580 if (!path) 1580 if (!path)
1962 /* don't want to free(env) as it contains the memory that backs 1962 /* don't want to free(env) as it contains the memory that backs
1963 * the envvals array of strings */ 1963 * the envvals array of strings */
1964 return envvals; 1964 return envvals;
1965} 1965}
1966 1966
1967static void parseenv() 1967static void parseenv(void)
1968{ 1968{
1969 qa_textrels = get_split_env("QA_TEXTRELS"); 1969 qa_textrels = get_split_env("QA_TEXTRELS");
1970 qa_execstack = get_split_env("QA_EXECSTACK"); 1970 qa_execstack = get_split_env("QA_EXECSTACK");
1971 qa_wx_load = get_split_env("QA_WX_LOAD"); 1971 qa_wx_load = get_split_env("QA_WX_LOAD");
1972} 1972}
1973 1973
1974#ifdef __PAX_UTILS_CLEANUP 1974#ifdef __PAX_UTILS_CLEANUP
1975static void cleanup() 1975static void cleanup(void)
1976{ 1976{
1977 free(out_format); 1977 free(out_format);
1978 free(qa_textrels); 1978 free(qa_textrels);
1979 free(qa_execstack); 1979 free(qa_execstack);
1980 free(qa_wx_load); 1980 free(qa_wx_load);

Legend:
Removed from v.1.183  
changed lines
  Added in v.1.185

  ViewVC Help
Powered by ViewVC 1.1.20