/[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.173 Revision 1.174
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.173 2007/01/18 00:26:34 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.174 2007/01/18 08:12:55 solar 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.173 2007/01/18 00:26:34 vapier Exp $"; 12static const char *rcsid = "$Id: scanelf.c,v 1.174 2007/01/18 08:12:55 solar Exp $";
13#define argv0 "scanelf" 13#define argv0 "scanelf"
14 14
15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+') 15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+')
16 16
17/* prototypes */ 17/* prototypes */
31static void *xmalloc(size_t size); 31static void *xmalloc(size_t size);
32static void *xrealloc(void *ptr, size_t size); 32static void *xrealloc(void *ptr, size_t size);
33static void xstrncat(char **dst, const char *src, size_t *curr_len, size_t n); 33static void xstrncat(char **dst, const char *src, size_t *curr_len, size_t n);
34#define xstrcat(dst,src,curr_len) xstrncat(dst,src,curr_len,0) 34#define xstrcat(dst,src,curr_len) xstrncat(dst,src,curr_len,0)
35static inline void xchrcat(char **dst, const char append, size_t *curr_len); 35static inline void xchrcat(char **dst, const char append, size_t *curr_len);
36static int rematch(const char *regex, const char *match, int cflags);
36 37
37/* variables to control behavior */ 38/* variables to control behavior */
38static char match_etypes[126] = ""; 39static char match_etypes[126] = "";
39static char *ldpaths[256]; 40static char *ldpaths[256];
40static char scan_ldpath = 0; 41static char scan_ldpath = 0;
74caddr_t ldcache = 0; 75caddr_t ldcache = 0;
75size_t ldcache_size = 0; 76size_t ldcache_size = 0;
76unsigned long setpax = 0UL; 77unsigned long setpax = 0UL;
77 78
78int has_objdump = 0; 79int has_objdump = 0;
79 80/* find the path to a file by name */
80static char *which(const char *fname) 81static char *which(const char *fname)
81{ 82{
82 static char fullpath[BUFSIZ]; 83 static char fullpath[BUFSIZ];
83 char *path, *p; 84 char *path, *p;
84 85
95 return (char *) fullpath; 96 return (char *) fullpath;
96 } 97 }
97 } 98 }
98 free(path); 99 free(path);
99 return NULL; 100 return NULL;
101}
102
103/* 1 on failue. 0 otherwise */
104static int rematch(const char *regex, const char *match, int cflags)
105{
106 regex_t preg;
107 int ret;
108
109 if ((match == NULL) || (regex == NULL))
110 return EXIT_FAILURE;
111
112
113 if ((ret = regcomp(&preg, regex, cflags))) {
114 char err[256];
115
116 if (regerror(ret, &preg, err, sizeof(err)))
117 fprintf(stderr, "regcomp failed: %s", err);
118 else
119 fprintf(stderr, "regcomp failed");
120
121 return EXIT_FAILURE;
122 }
123 ret = regexec(&preg, match, 0, NULL, 0);
124 regfree(&preg);
125
126 return ret;
100} 127}
101 128
102/* sub-funcs for scanelf_file() */ 129/* sub-funcs for scanelf_file() */
103static void scanelf_file_get_symtabs(elfobj *elf, void **sym, void **tab) 130static void scanelf_file_get_symtabs(elfobj *elf, void **sym, void **tab)
104{ 131{
955 warnf("%s: corrupt ELF symbols", elf->filename); \ 982 warnf("%s: corrupt ELF symbols", elf->filename); \
956 ++sym; \ 983 ++sym; \
957 continue; \ 984 continue; \
958 } \ 985 } \
959 /* debug display ... show all symbols and some extra info */ \ 986 /* debug display ... show all symbols and some extra info */ \
960 if (*ret == '*') { \ 987 if (gmatch ? rematch(ret, symname, REG_EXTENDED) == 0 : *ret == '*') { \
961 printf("%s(%s) %5lX %15s %s\n", \ 988 printf("%s(%s) %5lX %15s %s\n", \
962 ((*found_sym == 0) ? "\n\t" : "\t"), \ 989 ((*found_sym == 0) ? "\n\t" : "\t"), \
963 elf->base_filename, \ 990 elf->base_filename, \
964 (unsigned long)sym->st_size, \ 991 (unsigned long)sym->st_size, \
965 get_elfstttype(sym->st_info), \ 992 get_elfstttype(sym->st_info), \

Legend:
Removed from v.1.173  
changed lines
  Added in v.1.174

  ViewVC Help
Powered by ViewVC 1.1.20