/[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.273 Revision 1.274
1/* 1/*
2 * Copyright 2003-2012 Gentoo Foundation 2 * Copyright 2003-2012 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.273 2015/02/22 01:38:28 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.274 2015/02/22 02:27:39 vapier Exp $
5 * 5 *
6 * Copyright 2003-2012 Ned Ludd - <solar@gentoo.org> 6 * Copyright 2003-2012 Ned Ludd - <solar@gentoo.org>
7 * Copyright 2004-2012 Mike Frysinger - <vapier@gentoo.org> 7 * Copyright 2004-2012 Mike Frysinger - <vapier@gentoo.org>
8 */ 8 */
9 9
10static const char rcsid[] = "$Id: scanelf.c,v 1.273 2015/02/22 01:38:28 vapier Exp $"; 10static const char rcsid[] = "$Id: scanelf.c,v 1.274 2015/02/22 02:27:39 vapier Exp $";
11const char argv0[] = "scanelf"; 11const char argv0[] = "scanelf";
12 12
13#include "paxinc.h" 13#include "paxinc.h"
14 14
15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+') 15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+')
1067 1067
1068 return NULL; 1068 return NULL;
1069} 1069}
1070static char *scanelf_file_interp(elfobj *elf, char *found_interp) 1070static char *scanelf_file_interp(elfobj *elf, char *found_interp)
1071{ 1071{
1072 void *strtbl_void; 1072 uint64_t offset = 0;
1073 1073
1074 if (!show_interp) return NULL; 1074 if (!show_interp) return NULL;
1075 1075
1076 if (elf->phdr) {
1077 /* Walk all the program headers to find the PT_INTERP */
1078#define SHOW_PT_INTERP(B) \
1079 if (elf->elf_class == ELFCLASS ## B) { \
1080 size_t i; \
1081 Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \
1082 Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \
1083 for (i = 0; i < EGET(ehdr->e_phnum); ++i) { \
1084 if (EGET(phdr[i].p_type) == PT_INTERP) { \
1085 offset = EGET(phdr[i].p_offset); \
1086 break; \
1087 } \
1088 } \
1089 }
1090 SHOW_PT_INTERP(32)
1091 SHOW_PT_INTERP(64)
1092 } else if (elf->shdr) {
1093 /* Use the section headers to find it */
1076 strtbl_void = elf_findsecbyname(elf, ".interp"); 1094 void *strtbl_void = elf_findsecbyname(elf, ".interp");
1077 1095
1078 if (strtbl_void) {
1079#define SHOW_INTERP(B) \ 1096#define SHOW_INTERP(B) \
1080 if (elf->elf_class == ELFCLASS ## B) { \ 1097 if (elf->elf_class == ELFCLASS ## B) { \
1081 Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \ 1098 Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \
1082 *found_interp = 1; \ 1099 offset = EGET(strtbl->sh_offset); \
1083 return (be_wewy_wewy_quiet ? NULL : elf->data + EGET(strtbl->sh_offset)); \
1084 } 1100 }
1101 if (strtbl_void) {
1085 SHOW_INTERP(32) 1102 SHOW_INTERP(32)
1086 SHOW_INTERP(64) 1103 SHOW_INTERP(64)
1087 } else if (elf->phdr) {
1088 /* Walk all the program headers to find the PT_INTERP */
1089#define SHOW_PT_INTERP(B) \
1090 if (elf->elf_class == ELFCLASS ## B) { \
1091 unsigned long i; \
1092 Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \
1093 Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \
1094 for (i = 0; i < EGET(ehdr->e_phnum); i++) { \
1095 if (EGET(phdr[i].p_type) != PT_INTERP) \
1096 continue; \
1097 *found_interp = 1; \
1098 return (be_wewy_wewy_quiet ? NULL : elf->data + EGET(phdr[i].p_offset)); \
1099 } \
1100 } 1104 }
1101 SHOW_PT_INTERP(32) 1105 }
1102 SHOW_PT_INTERP(64) 1106
1107 /* Validate the pointer even if we don't use it in output */
1108 if (offset && offset <= (uint64_t)elf->len) {
1109 char *interp = elf->data + offset;
1110
1111 /* If it isn't a C pointer, it's garbage */
1112 if (memchr(interp, 0, elf->len - offset)) {
1113 *found_interp = 1;
1114 if (!be_wewy_wewy_quiet)
1115 return interp;
1116 }
1103 } 1117 }
1104 1118
1105 return NULL; 1119 return NULL;
1106} 1120}
1107static const char *scanelf_file_bind(elfobj *elf, char *found_bind) 1121static const char *scanelf_file_bind(elfobj *elf, char *found_bind)

Legend:
Removed from v.1.273  
changed lines
  Added in v.1.274

  ViewVC Help
Powered by ViewVC 1.1.20