/[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.248 Revision 1.249
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/scanelf.c,v 1.248 2012/11/04 07:48:42 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.249 2012/11/04 08:23:12 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.248 2012/11/04 07:48:42 vapier Exp $"; 10static const char rcsid[] = "$Id: scanelf.c,v 1.249 2012/11/04 08:23:12 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 == '+')
45static char be_verbose = 0; 45static char be_verbose = 0;
46static char be_wewy_wewy_quiet = 0; 46static char be_wewy_wewy_quiet = 0;
47static char be_semi_verbose = 0; 47static char be_semi_verbose = 0;
48static char *find_sym = NULL; 48static char *find_sym = NULL;
49static array_t _find_sym_arr = array_init_decl, *find_sym_arr = &_find_sym_arr; 49static array_t _find_sym_arr = array_init_decl, *find_sym_arr = &_find_sym_arr;
50static array_t _find_sym_regex_arr = array_init_decl, *find_sym_regex_arr = &_find_sym_regex_arr;
50static char *find_lib = NULL; 51static char *find_lib = NULL;
51static array_t _find_lib_arr = array_init_decl, *find_lib_arr = &_find_lib_arr; 52static array_t _find_lib_arr = array_init_decl, *find_lib_arr = &_find_lib_arr;
52static char *find_section = NULL; 53static char *find_section = NULL;
53static array_t _find_section_arr = array_init_decl, *find_section_arr = &_find_section_arr; 54static array_t _find_section_arr = array_init_decl, *find_section_arr = &_find_section_arr;
54static char *out_format = NULL; 55static char *out_format = NULL;
115 if (*path == '\0') 116 if (*path == '\0')
116 path = "."; 117 path = ".";
117 } 118 }
118 119
119 return path; 120 return path;
120}
121
122/* 1 on failure. 0 otherwise */
123static int rematch(const char *regex, const char *match, int cflags)
124{
125 regex_t preg;
126 int ret;
127
128 if ((match == NULL) || (regex == NULL))
129 return EXIT_FAILURE;
130
131 ret = regcomp(&preg, regex, cflags);
132 if (ret) {
133 char err[256];
134 regerror(ret, &preg, err, sizeof(err));
135 warnf("regcomp failed: %s", err);
136 return EXIT_FAILURE;
137 }
138 ret = regexec(&preg, match, 0, NULL, 0);
139 regfree(&preg);
140
141 return ret;
142} 121}
143 122
144/* sub-funcs for scanelf_fileat() */ 123/* sub-funcs for scanelf_fileat() */
145static void scanelf_file_get_symtabs(elfobj *elf, void **sym, void **str) 124static void scanelf_file_get_symtabs(elfobj *elf, void **sym, void **str)
146{ 125{
1255 goto matched; 1234 goto matched;
1256 1235
1257 } else { 1236 } else {
1258 if (g_match) { 1237 if (g_match) {
1259 /* regex match the symbol */ 1238 /* regex match the symbol */
1260 int flags = REG_EXTENDED | REG_NOSUB; 1239 if (regexec(find_sym_regex_arr->eles[n], symname, 0, NULL, 0) == REG_NOMATCH)
1261 if (g_match > 1)
1262 flags |= REG_ICASE;
1263 if (rematch(this_sym, symname, flags) != 0)
1264 continue; 1240 continue;
1265 1241
1266 } else if (*this_sym) { 1242 } else if (*this_sym) {
1267 /* give empty symbols a "pass", else do a normal compare */ 1243 /* give empty symbols a "pass", else do a normal compare */
1268 const size_t len = strlen(this_sym); 1244 const size_t len = strlen(this_sym);
2118 xarraypush_str(find_section_arr, optarg); 2094 xarraypush_str(find_section_arr, optarg);
2119 break; 2095 break;
2120 case 's': { 2096 case 's': {
2121 /* historically, this was comma delimited */ 2097 /* historically, this was comma delimited */
2122 char *this_sym = strtok(optarg, ","); 2098 char *this_sym = strtok(optarg, ",");
2099 if (!this_sym) /* edge case: -s '' */
2100 xarraypush_str(find_sym_arr, "");
2123 while (this_sym) { 2101 while (this_sym) {
2124 xarraypush_str(find_sym_arr, this_sym); 2102 xarraypush_str(find_sym_arr, this_sym);
2125 this_sym = strtok(NULL, ","); 2103 this_sym = strtok(NULL, ",");
2126 } 2104 }
2127 break; 2105 break;
2218 err("Unhandled option '%c'; please report this", i); 2196 err("Unhandled option '%c'; please report this", i);
2219 } 2197 }
2220 } 2198 }
2221 if (show_textrels && be_verbose) 2199 if (show_textrels && be_verbose)
2222 has_objdump = bin_in_path("objdump"); 2200 has_objdump = bin_in_path("objdump");
2201 /* precompile all the regexes */
2202 if (g_match) {
2203 regex_t preg;
2204 const char *this_sym;
2205 size_t n;
2206 int flags = REG_EXTENDED | REG_NOSUB | (g_match > 1 ? REG_ICASE : 0);
2207
2208 array_for_each(find_sym_arr, n, this_sym) {
2209 /* see scanelf_match_symname for logic info */
2210 switch (this_sym[0]) {
2211 case '%':
2212 while (*(this_sym++))
2213 if (*this_sym == '%') {
2214 ++this_sym;
2215 break;
2216 }
2217 break;
2218 case '+':
2219 case '-':
2220 ++this_sym;
2221 break;
2222 }
2223 if (*this_sym == '*')
2224 ++this_sym;
2225
2226 ret = regcomp(&preg, this_sym, flags);
2227 if (ret) {
2228 char err[256];
2229 regerror(ret, &preg, err, sizeof(err));
2230 err("regcomp of %s failed: %s", this_sym, err);
2231 }
2232 xarraypush(find_sym_regex_arr, &preg, sizeof(preg));
2233 }
2234 }
2223 /* flatten arrays for display */ 2235 /* flatten arrays for display */
2224 if (array_cnt(find_sym_arr)) 2236 if (array_cnt(find_sym_arr))
2225 find_sym = array_flatten_str(find_sym_arr); 2237 find_sym = array_flatten_str(find_sym_arr);
2226 if (array_cnt(find_lib_arr)) 2238 if (array_cnt(find_lib_arr))
2227 find_lib = array_flatten_str(find_lib_arr); 2239 find_lib = array_flatten_str(find_lib_arr);
2320 xarrayfree(find_lib_arr); 2332 xarrayfree(find_lib_arr);
2321 xarrayfree(find_section_arr); 2333 xarrayfree(find_section_arr);
2322 free(find_sym); 2334 free(find_sym);
2323 free(find_lib); 2335 free(find_lib);
2324 free(find_section); 2336 free(find_section);
2337 {
2338 size_t n;
2339 regex_t *preg;
2340 array_for_each(find_sym_regex_arr, n, preg)
2341 regfree(preg);
2342 xarrayfree(find_sym_regex_arr);
2343 }
2325 2344
2326 if (ldcache != 0) 2345 if (ldcache != 0)
2327 munmap(ldcache, ldcache_size); 2346 munmap(ldcache, ldcache_size);
2328 return ret; 2347 return ret;
2329} 2348}

Legend:
Removed from v.1.248  
changed lines
  Added in v.1.249

  ViewVC Help
Powered by ViewVC 1.1.20