/[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.100 Revision 1.101
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.100 2006/01/10 01:38:17 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.101 2006/01/10 01:40:15 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
12static const char *rcsid = "$Id: scanelf.c,v 1.100 2006/01/10 01:38:17 vapier Exp $"; 12static const char *rcsid = "$Id: scanelf.c,v 1.101 2006/01/10 01:40:15 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
51static char be_wewy_wewy_quiet = 0; 51static char be_wewy_wewy_quiet = 0;
52static char *find_sym = NULL, *versioned_symname = NULL; 52static char *find_sym = NULL, *versioned_symname = NULL;
53static char *find_lib = NULL; 53static char *find_lib = NULL;
54static char *out_format = NULL; 54static char *out_format = NULL;
55static char *search_path = NULL; 55static char *search_path = NULL;
56static char fix_elf = 0;
56static char gmatch = 0; 57static char gmatch = 0;
57static char printcache = 0; 58static char printcache = 0;
58 59
59 60
60caddr_t ldcache = 0; 61caddr_t ldcache = 0;
175 } else \ 176 } else \
176 continue; \ 177 continue; \
177 flags = EGET(phdr[i].p_flags); \ 178 flags = EGET(phdr[i].p_flags); \
178 if (be_quiet && ((flags & check_flags) != check_flags)) \ 179 if (be_quiet && ((flags & check_flags) != check_flags)) \
179 continue; \ 180 continue; \
181 if (fix_elf && ((flags & PF_X) != flags)) { \
182 ESET(phdr[i].p_flags, flags & (PF_X ^ (size_t)-1)); \
183 ret[3] = ret[7] = '!'; \
184 flags = EGET(phdr[i].p_flags); \
185 } \
180 memcpy(ret+offset, gnu_short_stack_flags(flags), 3); \ 186 memcpy(ret+offset, gnu_short_stack_flags(flags), 3); \
181 *found = 1; \ 187 *found = 1; \
182 ++shown; \ 188 ++shown; \
183 } \ 189 } \
184 } else if (elf->shdr != NULL) { \ 190 } else if (elf->shdr != NULL) { \
445 break; \ 451 break; \
446 else \ 452 else \
447 start = start + len + 1; \ 453 start = start + len + 1; \
448 } \ 454 } \
449 } \ 455 } \
456 if (*r) { \
450 if (*r) *found_rpath = 1; \ 457 *found_rpath = 1; \
458 if (fix_elf > 2 || *r == '\0') { \
459 /* just nuke it */ \
460 nuke_it##B: \
461 ESET(dyn->d_tag, DT_DEBUG); \
462 } else if (fix_elf) { \
463 /* try to clean "bad" paths */ \
464 size_t len, tmpdir_len; \
465 char *start, *end; \
466 const char *tmpdir; \
467 start = *r; \
468 tmpdir = (getenv("TMPDIR") ? : "."); \
469 tmpdir_len = strlen(tmpdir); \
470 while (1) { \
471 end = strchr(start, ':'); \
472 if (start == end) { \
473 eat_this_path##B: \
474 len = strlen(end); \
475 memmove(start, end+1, len); \
476 start[len-1] = '\0'; \
477 end = start - 1; \
478 } else if (tmpdir && !strncmp(start, tmpdir, tmpdir_len)) { \
479 if (!end) { \
480 if (start == *r) \
481 goto nuke_it##B; \
482 *--start = '\0'; \
483 } else \
484 goto eat_this_path##B; \
485 } \
486 if (!end) \
487 break; \
488 start = end + 1; \
489 } \
490 } \
491 } \
451 } \ 492 } \
452 ++dyn; \ 493 ++dyn; \
453 } \ 494 } \
454 } } 495 } }
455 SHOW_RPATH(32) 496 SHOW_RPATH(32)
822 found_pax = found_phdr = found_relro = found_load = found_textrel = \ 863 found_pax = found_phdr = found_relro = found_load = found_textrel = \
823 found_rpath = found_needed = found_interp = found_bind = found_soname = \ 864 found_rpath = found_needed = found_interp = found_bind = found_soname = \
824 found_sym = found_lib = found_file = found_textrels = 0; 865 found_sym = found_lib = found_file = found_textrels = 0;
825 866
826 /* verify this is real ELF */ 867 /* verify this is real ELF */
827 if ((elf = readelf(filename)) == NULL) { 868 if ((elf = _readelf(filename, !fix_elf)) == NULL) {
828 if (be_verbose > 2) printf("%s: not an ELF\n", filename); 869 if (be_verbose > 2) printf("%s: not an ELF\n", filename);
829 return; 870 return;
830 } 871 }
831 872
832 if (be_verbose > 1) 873 if (be_verbose > 1)
1105 free(path); 1146 free(path);
1106} 1147}
1107 1148
1108 1149
1109/* usage / invocation handling functions */ 1150/* usage / invocation handling functions */
1110#define PARSE_FLAGS "plRmyxetrnLibSs:gN:TaqvF:f:o:BhV" 1151#define PARSE_FLAGS "plRmyXxetrnLibSs:gN:TaqvF:f:o:BhV"
1111#define a_argument required_argument 1152#define a_argument required_argument
1112static struct option const long_opts[] = { 1153static struct option const long_opts[] = {
1113 {"path", no_argument, NULL, 'p'}, 1154 {"path", no_argument, NULL, 'p'},
1114 {"ldpath", no_argument, NULL, 'l'}, 1155 {"ldpath", no_argument, NULL, 'l'},
1115 {"recursive", no_argument, NULL, 'R'}, 1156 {"recursive", no_argument, NULL, 'R'},
1116 {"mount", no_argument, NULL, 'm'}, 1157 {"mount", no_argument, NULL, 'm'},
1117 {"symlink", no_argument, NULL, 'y'}, 1158 {"symlink", no_argument, NULL, 'y'},
1159 {"fix", no_argument, NULL, 'X'},
1118 {"pax", no_argument, NULL, 'x'}, 1160 {"pax", no_argument, NULL, 'x'},
1119 {"header", no_argument, NULL, 'e'}, 1161 {"header", no_argument, NULL, 'e'},
1120 {"textrel", no_argument, NULL, 't'}, 1162 {"textrel", no_argument, NULL, 't'},
1121 {"rpath", no_argument, NULL, 'r'}, 1163 {"rpath", no_argument, NULL, 'r'},
1122 {"needed", no_argument, NULL, 'n'}, 1164 {"needed", no_argument, NULL, 'n'},
1143static const char *opts_help[] = { 1185static const char *opts_help[] = {
1144 "Scan all directories in PATH environment", 1186 "Scan all directories in PATH environment",
1145 "Scan all directories in /etc/ld.so.conf", 1187 "Scan all directories in /etc/ld.so.conf",
1146 "Scan directories recursively", 1188 "Scan directories recursively",
1147 "Don't recursively cross mount points", 1189 "Don't recursively cross mount points",
1148 "Don't scan symlinks\n", 1190 "Don't scan symlinks",
1191 "Try and 'fix' bad things (use with -r/-e)\n",
1149 "Print PaX markings", 1192 "Print PaX markings",
1150 "Print GNU_STACK/PT_LOAD markings", 1193 "Print GNU_STACK/PT_LOAD markings",
1151 "Print TEXTREL information", 1194 "Print TEXTREL information",
1152 "Print RPATH information", 1195 "Print RPATH information",
1153 "Print NEEDED information", 1196 "Print NEEDED information",
1256 case 'B': show_banner = 0; break; 1299 case 'B': show_banner = 0; break;
1257 case 'l': scan_ldpath = 1; break; 1300 case 'l': scan_ldpath = 1; break;
1258 case 'p': scan_envpath = 1; break; 1301 case 'p': scan_envpath = 1; break;
1259 case 'R': dir_recurse = 1; break; 1302 case 'R': dir_recurse = 1; break;
1260 case 'm': dir_crossmount = 0; break; 1303 case 'm': dir_crossmount = 0; break;
1304 case 'X': ++fix_elf; break;
1261 case 'x': show_pax = 1; break; 1305 case 'x': show_pax = 1; break;
1262 case 'e': show_phdr = 1; break; 1306 case 'e': show_phdr = 1; break;
1263 case 't': show_textrel = 1; break; 1307 case 't': show_textrel = 1; break;
1264 case 'r': show_rpath = 1; break; 1308 case 'r': show_rpath = 1; break;
1265 case 'n': show_needed = 1; break; 1309 case 'n': show_needed = 1; break;

Legend:
Removed from v.1.100  
changed lines
  Added in v.1.101

  ViewVC Help
Powered by ViewVC 1.1.20