/[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.65 Revision 1.66
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/scanelf.c,v 1.65 2005/05/30 03:23:07 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.66 2005/06/01 22:37:38 vapier Exp $
5 * 5 *
6 ******************************************************************** 6 ********************************************************************
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as 8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the 9 * published by the Free Software Foundation; either version 2 of the
33#include <dirent.h> 33#include <dirent.h>
34#include <getopt.h> 34#include <getopt.h>
35#include <assert.h> 35#include <assert.h>
36#include "paxelf.h" 36#include "paxelf.h"
37 37
38static const char *rcsid = "$Id: scanelf.c,v 1.65 2005/05/30 03:23:07 vapier Exp $"; 38static const char *rcsid = "$Id: scanelf.c,v 1.66 2005/06/01 22:37:38 vapier Exp $";
39#define argv0 "scanelf" 39#define argv0 "scanelf"
40 40
41 41
42 42
43/* prototypes */ 43/* prototypes */
69static char show_banner = 1; 69static char show_banner = 1;
70static char be_quiet = 0; 70static char be_quiet = 0;
71static char be_verbose = 0; 71static char be_verbose = 0;
72static char *find_sym = NULL, *versioned_symname = NULL; 72static char *find_sym = NULL, *versioned_symname = NULL;
73static char *out_format = NULL; 73static char *out_format = NULL;
74static char *search_path = NULL;
74 75
75 76
76/* sub-funcs for scanelf_file() */ 77/* sub-funcs for scanelf_file() */
77static char *scanelf_file_pax(elfobj *elf, char *found_pax) 78static char *scanelf_file_pax(elfobj *elf, char *found_pax)
78{ 79{
484 for (i = 0; out_format[i]; ++i) { 485 for (i = 0; out_format[i]; ++i) {
485 if (out_format[i] != '%') continue; 486 if (out_format[i] != '%') continue;
486 487
487 switch (out_format[++i]) { 488 switch (out_format[++i]) {
488 case '%': break; 489 case '%': break;
490 case 'F':
491 case 'p':
489 case 'F': prints("FILE "); found_file = 1; break; 492 case 'f': prints("FILE "); found_file = 1; break;
490 case 'o': prints(" TYPE "); break; 493 case 'o': prints(" TYPE "); break;
491 case 'x': prints(" PAX "); break; 494 case 'x': prints(" PAX "); break;
492 case 'e': prints("STK/REL "); break; 495 case 'e': prints("STK/REL "); break;
493 case 't': prints("TEXTREL "); break; 496 case 't': prints("TEXTREL "); break;
494 case 'r': prints("RPATH "); break; 497 case 'r': prints("RPATH "); break;
505 } 508 }
506 509
507 /* dump all the good stuff */ 510 /* dump all the good stuff */
508 for (i = 0; out_format[i]; ++i) { 511 for (i = 0; out_format[i]; ++i) {
509 const char *out; 512 const char *out;
513 const char *tmp;
510 514
511 /* make sure we trim leading spaces in quiet mode */ 515 /* make sure we trim leading spaces in quiet mode */
512 if (be_quiet && *out_buffer == ' ' && !out_buffer[1]) 516 if (be_quiet && *out_buffer == ' ' && !out_buffer[1])
513 *out_buffer = '\0'; 517 *out_buffer = '\0';
514 518
519 523
520 out = NULL; 524 out = NULL;
521 switch (out_format[++i]) { 525 switch (out_format[++i]) {
522 case '%': xchrcat(&out_buffer, '%', &out_len); break; 526 case '%': xchrcat(&out_buffer, '%', &out_len); break;
523 case 'F': found_file = 1; xstrcat(&out_buffer, filename, &out_len); break; 527 case 'F': found_file = 1; xstrcat(&out_buffer, filename, &out_len); break;
528 case 'p':
529 found_file = 1;
530 tmp = filename;
531 if (search_path) {
532 ssize_t len_search = strlen(search_path);
533 ssize_t len_file = strlen(filename);
534 if (!strncmp(filename, search_path, len_search) && \
535 len_file > len_search)
536 tmp += len_search;
537 if (*tmp == '/' && search_path[len_search-1] == '/') tmp++;
538 }
539 xstrcat(&out_buffer, tmp, &out_len);
540 break;
541 case 'f':
542 found_file = 1;
543 tmp = strrchr(filename, '/');
544 tmp = (tmp == NULL ? filename : tmp+1);
545 xstrcat(&out_buffer, tmp, &out_len);
546 break;
524 case 'o': out = get_elfetype(elf); break; 547 case 'o': out = get_elfetype(elf); break;
525 case 'x': out = scanelf_file_pax(elf, &found_pax); break; 548 case 'x': out = scanelf_file_pax(elf, &found_pax); break;
526 case 'e': out = scanelf_file_stack(elf, &found_stack, &found_relro); break; 549 case 'e': out = scanelf_file_stack(elf, &found_stack, &found_relro); break;
527 case 't': out = scanelf_file_textrel(elf, &found_textrel); break; 550 case 't': out = scanelf_file_textrel(elf, &found_textrel); break;
528 case 'r': scanelf_file_rpath(elf, &found_rpath, &out_buffer, &out_len); break; 551 case 'r': scanelf_file_rpath(elf, &found_rpath, &out_buffer, &out_len); break;
610 return 1; 633 return 1;
611 634
612 while ((fgets(path, _POSIX_PATH_MAX, fp)) != NULL) { 635 while ((fgets(path, _POSIX_PATH_MAX, fp)) != NULL) {
613 if ((p = strchr(path, '\n')) != NULL) 636 if ((p = strchr(path, '\n')) != NULL)
614 *p = 0; 637 *p = 0;
638 search_path = path;
615 scanelf_dir(path); 639 scanelf_dir(path);
616 } 640 }
617 if (fp != stdin) 641 if (fp != stdin)
618 fclose(fp); 642 fclose(fp);
619 return 0; 643 return 0;
767 791
768 puts("\nThe format modifiers for the -F option are:"); 792 puts("\nThe format modifiers for the -F option are:");
769 puts(" %F Filename \t%x PaX Flags \t%e STACK/RELRO"); 793 puts(" %F Filename \t%x PaX Flags \t%e STACK/RELRO");
770 puts(" %t TEXTREL \t%r RPATH \t%n NEEDED"); 794 puts(" %t TEXTREL \t%r RPATH \t%n NEEDED");
771 puts(" %i INTERP \t%b BIND \t%s symbol"); 795 puts(" %i INTERP \t%b BIND \t%s symbol");
796 puts(" %p filename (with search path removed)");
797 puts(" %f base filename");
772 798
773 exit(status); 799 exit(status);
774} 800}
775 801
776/* parse command line arguments and preform needed actions */ 802/* parse command line arguments and preform needed actions */
853 if (out_format[i] != '%') continue; 879 if (out_format[i] != '%') continue;
854 880
855 switch (out_format[++i]) { 881 switch (out_format[++i]) {
856 case '%': break; 882 case '%': break;
857 case 'F': break; 883 case 'F': break;
884 case 'p': break;
885 case 'f': break;
858 case 's': break; 886 case 's': break;
859 case 'o': break; 887 case 'o': break;
860 case 'x': show_pax = 1; break; 888 case 'x': show_pax = 1; break;
861 case 'e': show_stack = 1; break; 889 case 'e': show_stack = 1; break;
862 case 't': show_textrel = 1; break; 890 case 't': show_textrel = 1; break;
897 free(from_file); 925 free(from_file);
898 from_file = *argv; 926 from_file = *argv;
899 } 927 }
900 if (optind == argc && !scan_ldpath && !scan_envpath && !from_file) 928 if (optind == argc && !scan_ldpath && !scan_envpath && !from_file)
901 err("Nothing to scan !?"); 929 err("Nothing to scan !?");
902 while (optind < argc) 930 while (optind < argc) {
903 scanelf_dir(argv[optind++]); 931 search_path = argv[optind++];
932 scanelf_dir(search_path);
933 }
904 934
905 /* clean up */ 935 /* clean up */
906 if (find_sym) { 936 if (find_sym) {
907 free(find_sym); 937 free(find_sym);
908 free(versioned_symname); 938 free(versioned_symname);
958 if (argc < 2) 988 if (argc < 2)
959 usage(EXIT_FAILURE); 989 usage(EXIT_FAILURE);
960 parseargs(argc, argv); 990 parseargs(argc, argv);
961 fclose(stdout); 991 fclose(stdout);
962#ifdef __BOUNDS_CHECKING_ON 992#ifdef __BOUNDS_CHECKING_ON
963 warn("The calls to add/delete heap should be off by 1 due to the out_buffer not being freed in scanelf_file()"); 993 warn("The calls to add/delete heap should be off by 1 due to the out_buffer not being freed in scanelf_file()");
964#endif 994#endif
965 return EXIT_SUCCESS; 995 return EXIT_SUCCESS;
966} 996}

Legend:
Removed from v.1.65  
changed lines
  Added in v.1.66

  ViewVC Help
Powered by ViewVC 1.1.20