| 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.102 2006/01/11 01:12:12 vapier Exp $ |
4 | * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.103 2006/01/11 23:46:21 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.102 2006/01/11 01:12:12 vapier Exp $"; |
12 | static const char *rcsid = "$Id: scanelf.c,v 1.103 2006/01/11 23:46:21 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 | |
| … | |
… | |
| 427 | /* Verify the memory is somewhat sane */ \ |
427 | /* Verify the memory is somewhat sane */ \ |
| 428 | offset = EGET(strtbl->sh_offset) + EGET(dyn->d_un.d_ptr); \ |
428 | offset = EGET(strtbl->sh_offset) + EGET(dyn->d_un.d_ptr); \ |
| 429 | if (offset < (Elf ## B ## _Off)elf->len) { \ |
429 | if (offset < (Elf ## B ## _Off)elf->len) { \ |
| 430 | if (*r) warn("ELF has multiple %s's !?", get_elfdtype(word)); \ |
430 | if (*r) warn("ELF has multiple %s's !?", get_elfdtype(word)); \ |
| 431 | *r = (char*)(elf->data + offset); \ |
431 | *r = (char*)(elf->data + offset); \ |
|
|
432 | /* cache the length in case we need to nuke this section later on */ \ |
|
|
433 | if (fix_elf) \ |
|
|
434 | offset = strlen(*r); \ |
| 432 | /* If quiet, don't output paths in ld.so.conf */ \ |
435 | /* If quiet, don't output paths in ld.so.conf */ \ |
| 433 | if (be_quiet) { \ |
436 | if (be_quiet) { \ |
| 434 | size_t len; \ |
437 | size_t len; \ |
| 435 | char *start, *end; \ |
438 | char *start, *end; \ |
| 436 | /* note that we only 'chop' off leading known paths. */ \ |
439 | /* note that we only 'chop' off leading known paths. */ \ |
| … | |
… | |
| 459 | } \ |
462 | } \ |
| 460 | if (*r) { \ |
463 | if (*r) { \ |
| 461 | if (fix_elf > 2 || **r == '\0') { \ |
464 | if (fix_elf > 2 || **r == '\0') { \ |
| 462 | /* just nuke it */ \ |
465 | /* just nuke it */ \ |
| 463 | nuke_it##B: \ |
466 | nuke_it##B: \ |
|
|
467 | memset(*r, 0x00, offset); \ |
| 464 | *r = NULL; \ |
468 | *r = NULL; \ |
| 465 | ESET(dyn->d_tag, DT_DEBUG); \ |
469 | ESET(dyn->d_tag, DT_DEBUG); \ |
|
|
470 | ESET(dyn->d_un.d_ptr, 0); \ |
| 466 | } else if (fix_elf) { \ |
471 | } else if (fix_elf) { \ |
| 467 | /* try to clean "bad" paths */ \ |
472 | /* try to clean "bad" paths */ \ |
| 468 | size_t len, tmpdir_len; \ |
473 | size_t len, tmpdir_len; \ |
| 469 | char *start, *end; \ |
474 | char *start, *end; \ |
| 470 | const char *tmpdir; \ |
475 | const char *tmpdir; \ |