/[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.94 Revision 1.95
1/* 1/*
2 * Copyright 2003-2005 Gentoo Foundation 2 * Copyright 2003-2005 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.94 2005/12/10 04:10:26 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.95 2005/12/10 06:08:22 vapier Exp $
5 * 5 *
6 * Copyright 2003-2005 Ned Ludd - <solar@gentoo.org> 6 * Copyright 2003-2005 Ned Ludd - <solar@gentoo.org>
7 * Copyright 2004-2005 Mike Frysinger - <vapier@gentoo.org> 7 * Copyright 2004-2005 Mike Frysinger - <vapier@gentoo.org>
8 */ 8 */
9 9
19#include <dirent.h> 19#include <dirent.h>
20#include <getopt.h> 20#include <getopt.h>
21#include <assert.h> 21#include <assert.h>
22#include "paxinc.h" 22#include "paxinc.h"
23 23
24static const char *rcsid = "$Id: scanelf.c,v 1.94 2005/12/10 04:10:26 vapier Exp $"; 24static const char *rcsid = "$Id: scanelf.c,v 1.95 2005/12/10 06:08:22 vapier Exp $";
25#define argv0 "scanelf" 25#define argv0 "scanelf"
26 26
27#define IS_MODIFIER(c) (c == '%' || c == '#') 27#define IS_MODIFIER(c) (c == '%' || c == '#')
28 28
29 29
35static void scanelf_envpath(); 35static void scanelf_envpath();
36static void usage(int status); 36static void usage(int status);
37static void parseargs(int argc, char *argv[]); 37static void parseargs(int argc, char *argv[]);
38static char *xstrdup(const char *s); 38static char *xstrdup(const char *s);
39static void *xmalloc(size_t size); 39static void *xmalloc(size_t size);
40static void xstrcat(char **dst, const char *src, size_t *curr_len); 40static void xstrncat(char **dst, const char *src, size_t *curr_len, size_t n);
41#define xstrcat(dst,src,curr_len) xstrncat(dst,src,curr_len,0)
41static inline void xchrcat(char **dst, const char append, size_t *curr_len); 42static inline void xchrcat(char **dst, const char append, size_t *curr_len);
42 43
43/* variables to control behavior */ 44/* variables to control behavior */
44static char *ldpaths[256]; 45static char *ldpaths[256];
45static char scan_ldpath = 0; 46static char scan_ldpath = 0;
643 return NULL; 644 return NULL;
644} 645}
645static char *scanelf_file_sym(elfobj *elf, char *found_sym) 646static char *scanelf_file_sym(elfobj *elf, char *found_sym)
646{ 647{
647 unsigned long i; 648 unsigned long i;
649 char *ret;
648 void *symtab_void, *strtab_void; 650 void *symtab_void, *strtab_void;
649 651
650 if (!find_sym) return NULL; 652 if (!find_sym) return NULL;
653 ret = find_sym;
651 654
652 scanelf_file_get_symtabs(elf, &symtab_void, &strtab_void); 655 scanelf_file_get_symtabs(elf, &symtab_void, &strtab_void);
653 656
654 if (symtab_void && strtab_void) { 657 if (symtab_void && strtab_void) {
655#define FIND_SYM(B) \ 658#define FIND_SYM(B) \
665 if (*find_sym == '*') { \ 668 if (*find_sym == '*') { \
666 printf("%s(%s) %5lX %15s %s\n", \ 669 printf("%s(%s) %5lX %15s %s\n", \
667 ((*found_sym == 0) ? "\n\t" : "\t"), \ 670 ((*found_sym == 0) ? "\n\t" : "\t"), \
668 elf->base_filename, \ 671 elf->base_filename, \
669 (unsigned long)sym->st_size, \ 672 (unsigned long)sym->st_size, \
670 (char *)get_elfstttype(sym->st_info), \ 673 get_elfstttype(sym->st_info), \
671 symname); \ 674 symname); \
672 *found_sym = 1; \ 675 *found_sym = 1; \
673 } else if ((strcmp(find_sym, symname) == 0) || \ 676 } else { \
677 char *this_sym, *next_sym; \
678 this_sym = find_sym; \
679 do { \
680 next_sym = strchr(this_sym, ','); \
681 if (next_sym == NULL) \
682 next_sym = this_sym + strlen(this_sym); \
683 if ((strncmp(this_sym, symname, (next_sym-this_sym)) == 0 && symname[next_sym-this_sym] == '\0') || \
674 (strcmp(symname, versioned_symname) == 0)) \ 684 (strcmp(symname, versioned_symname) == 0)) { \
685 ret = this_sym; \
675 (*found_sym)++; \ 686 (*found_sym)++; \
687 goto break_out; \
688 } \
689 this_sym = next_sym + 1; \
690 } while (*next_sym != '\0'); \
691 } \
676 } \ 692 } \
677 ++sym; \ 693 ++sym; \
678 } } 694 } }
679 FIND_SYM(32) 695 FIND_SYM(32)
680 FIND_SYM(64) 696 FIND_SYM(64)
681 } 697 }
682 698
699break_out:
683 if (be_wewy_wewy_quiet) return NULL; 700 if (be_wewy_wewy_quiet) return NULL;
684 701
685 if (*find_sym != '*' && *found_sym) 702 if (*find_sym != '*' && *found_sym)
686 return find_sym; 703 return ret;
687 if (be_quiet) 704 if (be_quiet)
688 return NULL; 705 return NULL;
689 else 706 else
690 return (char *)" - "; 707 return (char *)" - ";
691} 708}
831 case 'b': out = scanelf_file_bind(elf, &found_bind); break; 848 case 'b': out = scanelf_file_bind(elf, &found_bind); break;
832 case 'S': out = scanelf_file_soname(elf, &found_soname); break; 849 case 'S': out = scanelf_file_soname(elf, &found_soname); break;
833 case 's': out = scanelf_file_sym(elf, &found_sym); break; 850 case 's': out = scanelf_file_sym(elf, &found_sym); break;
834 default: warnf("'%c' has no scan code?", out_format[i]); 851 default: warnf("'%c' has no scan code?", out_format[i]);
835 } 852 }
853 if (out) {
854 /* hack for comma delimited output like `scanelf -s sym1,sym2,sym3` */
855 if (out_format[i] == 's' && (tmp=strchr(out,',')) != NULL)
856 xstrncat(&out_buffer, out, &out_len, (tmp-out));
857 else
836 if (out) xstrcat(&out_buffer, out, &out_len); 858 xstrcat(&out_buffer, out, &out_len);
859 }
837 } 860 }
838 861
839#define FOUND_SOMETHING() \ 862#define FOUND_SOMETHING() \
840 (found_pax || found_phdr || found_relro || found_load || found_textrel || \ 863 (found_pax || found_phdr || found_relro || found_load || found_textrel || \
841 found_rpath || found_needed || found_interp || found_bind || \ 864 found_rpath || found_needed || found_interp || found_bind || \
1252{ 1275{
1253 char *ret = strdup(s); 1276 char *ret = strdup(s);
1254 if (!ret) err("Could not strdup(): %s", strerror(errno)); 1277 if (!ret) err("Could not strdup(): %s", strerror(errno));
1255 return ret; 1278 return ret;
1256} 1279}
1257
1258static void *xmalloc(size_t size) 1280static void *xmalloc(size_t size)
1259{ 1281{
1260 void *ret = malloc(size); 1282 void *ret = malloc(size);
1261 if (!ret) err("Could not malloc() %li bytes", (unsigned long)size); 1283 if (!ret) err("Could not malloc() %li bytes", (unsigned long)size);
1262 return ret; 1284 return ret;
1263} 1285}
1264
1265static void xstrcat(char **dst, const char *src, size_t *curr_len) 1286static void xstrncat(char **dst, const char *src, size_t *curr_len, size_t n)
1266{ 1287{
1267 size_t new_len; 1288 size_t new_len;
1268 1289
1269 new_len = strlen(*dst) + strlen(src); 1290 new_len = strlen(*dst) + strlen(src);
1270 if (*curr_len <= new_len) { 1291 if (*curr_len <= new_len) {
1271 *curr_len = new_len + (*curr_len / 2); 1292 *curr_len = new_len + (*curr_len / 2);
1272 *dst = realloc(*dst, *curr_len); 1293 *dst = realloc(*dst, *curr_len);
1273 if (!*dst) 1294 if (!*dst)
1274 err("could not realloc %li bytes", (unsigned long)*curr_len); 1295 err("could not realloc() %li bytes", (unsigned long)*curr_len);
1275 } 1296 }
1276 1297
1298 if (n)
1299 strncat(*dst, src, n);
1300 else
1277 strcat(*dst, src); 1301 strcat(*dst, src);
1278} 1302}
1279
1280static inline void xchrcat(char **dst, const char append, size_t *curr_len) 1303static inline void xchrcat(char **dst, const char append, size_t *curr_len)
1281{ 1304{
1282 static char my_app[2]; 1305 static char my_app[2];
1283 my_app[0] = append; 1306 my_app[0] = append;
1284 my_app[1] = '\0'; 1307 my_app[1] = '\0';

Legend:
Removed from v.1.94  
changed lines
  Added in v.1.95

  ViewVC Help
Powered by ViewVC 1.1.20