/[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.261 Revision 1.262
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.261 2014/03/20 07:59:27 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.262 2014/03/20 08:06:01 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.261 2014/03/20 07:59:27 vapier Exp $"; 10static const char rcsid[] = "$Id: scanelf.c,v 1.262 2014/03/20 08:06:01 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 == '+')
16 16
17/* prototypes */ 17/* prototypes */
18static int file_matches_list(const char *filename, char **matchlist); 18static int file_matches_list(const char *filename, char **matchlist);
19 19
20/* variables to control behavior */ 20/* variables to control behavior */
21static char *match_etypes = NULL; 21static array_t _match_etypes = array_init_decl, *match_etypes = &_match_etypes;
22static array_t _ldpaths = array_init_decl, *ldpaths = &_ldpaths; 22static array_t _ldpaths = array_init_decl, *ldpaths = &_ldpaths;
23static char scan_ldpath = 0; 23static char scan_ldpath = 0;
24static char scan_envpath = 0; 24static char scan_envpath = 0;
25static char scan_symlink = 1; 25static char scan_symlink = 1;
26static char scan_archives = 0; 26static char scan_archives = 0;
1548 1548
1549/* scan a single elf */ 1549/* scan a single elf */
1550static int scanelf_elf(const char *filename, int fd, size_t len) 1550static int scanelf_elf(const char *filename, int fd, size_t len)
1551{ 1551{
1552 int ret = 1; 1552 int ret = 1;
1553 size_t n;
1554 const char *match_etype;
1553 elfobj *elf; 1555 elfobj *elf;
1554 1556
1555 /* verify this is real ELF */ 1557 /* verify this is real ELF */
1556 if ((elf = _readelf_fd(filename, fd, len, !fix_elf)) == NULL) { 1558 if ((elf = _readelf_fd(filename, fd, len, !fix_elf)) == NULL) {
1557 if (be_verbose > 2) printf("%s: not an ELF\n", filename); 1559 if (be_verbose > 2) printf("%s: not an ELF\n", filename);
1566 if (elf->elf_class != ELFCLASS64) 1568 if (elf->elf_class != ELFCLASS64)
1567 goto label_done; 1569 goto label_done;
1568 break; 1570 break;
1569 default: break; 1571 default: break;
1570 } 1572 }
1571 if (match_etypes) { 1573
1572 char sbuf[126]; 1574 array_for_each(match_etypes, n, match_etype)
1573 strncpy(sbuf, match_etypes, sizeof(sbuf));
1574 if (strchr(match_etypes, ',') != NULL) {
1575 char *p;
1576 while ((p = strrchr(sbuf, ',')) != NULL) {
1577 *p = 0;
1578 if (etype_lookup(p+1) == get_etype(elf)) 1575 if (etype_lookup(match_etype) == get_etype(elf))
1579 goto label_ret; 1576 goto label_ret;
1580 } 1577 if (array_cnt(match_etypes))
1581 }
1582 if (etype_lookup(sbuf) != get_etype(elf))
1583 goto label_done; 1578 goto label_done;
1584 }
1585 1579
1586label_ret: 1580label_ret:
1587 ret = scanelf_elfobj(elf); 1581 ret = scanelf_elfobj(elf);
1588 1582
1589label_done: 1583label_done:
2078 flags |= PF_NO##flag; \ 2072 flags |= PF_NO##flag; \
2079 } else { \ 2073 } else { \
2080 flags &= ~PF_NO##flag; \ 2074 flags &= ~PF_NO##flag; \
2081 flags |= PF_##flag; \ 2075 flags |= PF_##flag; \
2082 } 2076 }
2077static void parse_delimited(array_t *arr, char *arg, const char *delim)
2078{
2079 char *ele = strtok(arg, delim);
2080 if (!ele) /* edge case: -s '' */
2081 xarraypush_str(arr, "");
2082 while (ele) {
2083 xarraypush_str(arr, ele);
2084 ele = strtok(NULL, delim);
2085 }
2086}
2083static int parseargs(int argc, char *argv[]) 2087static int parseargs(int argc, char *argv[])
2084{ 2088{
2085 int i; 2089 int i;
2086 const char *from_file = NULL; 2090 const char *from_file = NULL;
2087 int ret = 0; 2091 int ret = 0;
2101 case 'f': 2105 case 'f':
2102 if (from_file) warn("You prob don't want to specify -f twice"); 2106 if (from_file) warn("You prob don't want to specify -f twice");
2103 from_file = optarg; 2107 from_file = optarg;
2104 break; 2108 break;
2105 case 'E': 2109 case 'E':
2106 match_etypes = optarg; 2110 /* historically, this was comma delimited */
2111 parse_delimited(match_etypes, optarg, ",");
2107 break; 2112 break;
2108 case 'M': 2113 case 'M':
2109 match_bits = atoi(optarg); 2114 match_bits = atoi(optarg);
2110 if (match_bits == 0) { 2115 if (match_bits == 0) {
2111 if (strcmp(optarg, "ELFCLASS32") == 0) 2116 if (strcmp(optarg, "ELFCLASS32") == 0)
2124 break; 2129 break;
2125 } 2130 }
2126 case 'k': 2131 case 'k':
2127 xarraypush_str(find_section_arr, optarg); 2132 xarraypush_str(find_section_arr, optarg);
2128 break; 2133 break;
2129 case 's': { 2134 case 's':
2130 /* historically, this was comma delimited */ 2135 /* historically, this was comma delimited */
2131 char *this_sym = strtok(optarg, ","); 2136 parse_delimited(find_sym_arr, optarg, ",");
2132 if (!this_sym) /* edge case: -s '' */
2133 xarraypush_str(find_sym_arr, "");
2134 while (this_sym) {
2135 xarraypush_str(find_sym_arr, this_sym);
2136 this_sym = strtok(NULL, ",");
2137 }
2138 break; 2137 break;
2139 }
2140 case 'N': 2138 case 'N':
2141 xarraypush_str(find_lib_arr, optarg); 2139 xarraypush_str(find_lib_arr, optarg);
2142 break; 2140 break;
2143 case 'F': { 2141 case 'F': {
2144 if (out_format) warn("You prob don't want to specify -F twice"); 2142 if (out_format) warn("You prob don't want to specify -F twice");

Legend:
Removed from v.1.261  
changed lines
  Added in v.1.262

  ViewVC Help
Powered by ViewVC 1.1.20