| 1 | /* |
1 | /* |
| 2 | * Copyright 2003-2006 Gentoo Foundation |
2 | * Copyright 2003-2006 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/scanelf.c,v 1.117 2006/01/28 19:47:47 solar Exp $ |
4 | * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.118 2006/02/03 00:10:05 vapier Exp $ |
| 5 | * |
5 | * |
| 6 | * Copyright 2003-2006 Ned Ludd - <solar@gentoo.org> |
6 | * Copyright 2003-2006 Ned Ludd - <solar@gentoo.org> |
| 7 | * Copyright 2004-2006 Mike Frysinger - <vapier@gentoo.org> |
7 | * Copyright 2004-2006 Mike Frysinger - <vapier@gentoo.org> |
| 8 | */ |
8 | */ |
| 9 | |
9 | |
| 10 | #include "paxinc.h" |
10 | #include "paxinc.h" |
| 11 | |
11 | |
| 12 | static const char *rcsid = "$Id: scanelf.c,v 1.117 2006/01/28 19:47:47 solar Exp $"; |
12 | static const char *rcsid = "$Id: scanelf.c,v 1.118 2006/02/03 00:10:05 vapier Exp $"; |
| 13 | #define argv0 "scanelf" |
13 | #define argv0 "scanelf" |
| 14 | |
14 | |
| 15 | #define IS_MODIFIER(c) (c == '%' || c == '#') |
15 | #define IS_MODIFIER(c) (c == '%' || c == '#') |
| 16 | |
16 | |
| 17 | |
17 | |
| … | |
… | |
| 196 | } else if (elf->shdr != NULL) { \ |
196 | } else if (elf->shdr != NULL) { \ |
| 197 | /* no program headers which means this is prob an object file */ \ |
197 | /* no program headers which means this is prob an object file */ \ |
| 198 | Elf ## B ## _Shdr *shdr = SHDR ## B (elf->shdr); \ |
198 | Elf ## B ## _Shdr *shdr = SHDR ## B (elf->shdr); \ |
| 199 | Elf ## B ## _Shdr *strtbl = shdr + EGET(ehdr->e_shstrndx); \ |
199 | Elf ## B ## _Shdr *strtbl = shdr + EGET(ehdr->e_shstrndx); \ |
| 200 | char *str; \ |
200 | char *str; \ |
| 201 | if ((void*)strtbl > (void*)(elf->data + sizeof(*strtbl))) \ |
201 | if ((void*)strtbl > (void*)elf->data_end) \ |
| 202 | goto skip_this_shdr##B; \ |
202 | goto skip_this_shdr##B; \ |
| 203 | check_flags = SHF_WRITE|SHF_EXECINSTR; \ |
203 | check_flags = SHF_WRITE|SHF_EXECINSTR; \ |
| 204 | for (i = 0; i < EGET(ehdr->e_shnum); ++i) { \ |
204 | for (i = 0; i < EGET(ehdr->e_shnum); ++i) { \ |
| 205 | if (EGET(shdr[i].sh_type) != SHT_PROGBITS) continue; \ |
205 | if (EGET(shdr[i].sh_type) != SHT_PROGBITS) continue; \ |
| 206 | offset = EGET(strtbl->sh_offset) + EGET(shdr[i].sh_name); \ |
206 | offset = EGET(strtbl->sh_offset) + EGET(shdr[i].sh_name); \ |