/[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.68 Revision 1.69
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.68 2005/06/03 15:03:25 solar Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.69 2005/06/03 23:18:01 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.68 2005/06/03 15:03:25 solar Exp $"; 38static const char *rcsid = "$Id: scanelf.c,v 1.69 2005/06/03 23:18:01 vapier Exp $";
39#define argv0 "scanelf" 39#define argv0 "scanelf"
40 40
41 41
42 42
43/* prototypes */ 43/* prototypes */
200 else 200 else
201 return (char *)" - "; 201 return (char *)" - ";
202} 202}
203static void scanelf_file_rpath(elfobj *elf, char *found_rpath, char **ret, size_t *ret_len) 203static void scanelf_file_rpath(elfobj *elf, char *found_rpath, char **ret, size_t *ret_len)
204{ 204{
205 /* TODO: when checking RPATH entries, check each subpath (between :) in ld.so.conf */
206 unsigned long i, s; 205 unsigned long i, s;
207 char *rpath, *runpath, **r; 206 char *rpath, *runpath, **r;
208 void *strtbl_void; 207 void *strtbl_void;
209 208
210 if (!show_rpath) return; 209 if (!show_rpath) return;
238 ++dyn; \ 237 ++dyn; \
239 continue; \ 238 continue; \
240 } \ 239 } \
241 /* Verify the memory is somewhat sane */ \ 240 /* Verify the memory is somewhat sane */ \
242 offset = EGET(strtbl->sh_offset) + EGET(dyn->d_un.d_ptr); \ 241 offset = EGET(strtbl->sh_offset) + EGET(dyn->d_un.d_ptr); \
243 if (offset < elf->len) { \ 242 if (offset < (Elf ## B ## _Off)elf->len) { \
244 if (*r) warn("ELF has multiple %s's !?", get_elfdtype(word)); \ 243 if (*r) warn("ELF has multiple %s's !?", get_elfdtype(word)); \
245 *r = (char*)(elf->data + offset); \ 244 *r = (char*)(elf->data + offset); \
246 /* If quiet, don't output paths in ld.so.conf */ \ 245 /* If quiet, don't output paths in ld.so.conf */ \
247 if (be_quiet) \ 246 if (be_quiet) { \
247 size_t len; \
248 char *start, *end; \
248 for (s = 0; ldpaths[s]; ++s) \ 249 for (s = 0; *r && ldpaths[s]; ++s) { \
249 if (!strcmp(ldpaths[s], *r)) { \ 250 /* scan each path in : delimited list */ \
250 *r = NULL; \ 251 start = *r; \
252 end = strchr(start, ':'); \
253 while ((start && ((end = strchr(start, ':')) != NULL)) || start) { \
254 len = (end ? abs(end - start) : strlen(start)); \
255 if (!strncmp(ldpaths[s], start, len) && !ldpaths[s][len]) { \
256 *r = (end ? end + 1 : NULL); \
251 break; \ 257 break; \
258 } \
259 start = (end ? start + len + 1 : NULL); \
252 } \ 260 } \
261 } \
262 } \
253 if (*r) *found_rpath = 1; \ 263 if (*r) *found_rpath = 1; \
254 } \ 264 } \
255 ++dyn; \ 265 ++dyn; \
256 } \ 266 } \
257 } } 267 } }
299 if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) continue; \ 309 if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) continue; \
300 dyn = DYN ## B (elf->data + offset); \ 310 dyn = DYN ## B (elf->data + offset); \
301 while (EGET(dyn->d_tag) != DT_NULL) { \ 311 while (EGET(dyn->d_tag) != DT_NULL) { \
302 if (EGET(dyn->d_tag) == DT_NEEDED) { \ 312 if (EGET(dyn->d_tag) == DT_NEEDED) { \
303 offset = EGET(strtbl->sh_offset) + EGET(dyn->d_un.d_ptr); \ 313 offset = EGET(strtbl->sh_offset) + EGET(dyn->d_un.d_ptr); \
304 if (offset >= elf->len) { \ 314 if (offset >= (Elf ## B ## _Off)elf->len) { \
305 ++dyn; \ 315 ++dyn; \
306 continue; \ 316 continue; \
307 } \ 317 } \
308 needed = (char*)(elf->data + offset); \ 318 needed = (char*)(elf->data + offset); \
309 if (*found_needed) xchrcat(ret, ',', ret_len); \ 319 if (*found_needed) xchrcat(ret, ',', ret_len); \
472 return; 482 return;
473 } 483 }
474 484
475 if (be_verbose > 1) 485 if (be_verbose > 1)
476 printf("%s: scanning file {%s,%s}\n", filename, 486 printf("%s: scanning file {%s,%s}\n", filename,
477 get_elfeitype(elf, EI_CLASS, elf->elf_class), 487 get_elfeitype(EI_CLASS, elf->elf_class),
478 get_elfeitype(elf, EI_DATA, elf->data[EI_DATA])); 488 get_elfeitype(EI_DATA, elf->data[EI_DATA]));
479 else if (be_verbose) 489 else if (be_verbose)
480 printf("%s: scanning file\n", filename); 490 printf("%s: scanning file\n", filename);
481 491
482 /* init output buffer */ 492 /* init output buffer */
483 if (!out_buffer) { 493 if (!out_buffer) {
965 return ret; 975 return ret;
966} 976}
967 977
968static void xstrcat(char **dst, const char *src, size_t *curr_len) 978static void xstrcat(char **dst, const char *src, size_t *curr_len)
969{ 979{
970 long new_len; 980 size_t new_len;
971 981
972 new_len = strlen(*dst) + strlen(src); 982 new_len = strlen(*dst) + strlen(src);
973 if (*curr_len <= new_len) { 983 if (*curr_len <= new_len) {
974 *curr_len = new_len + (*curr_len / 2); 984 *curr_len = new_len + (*curr_len / 2);
975 *dst = realloc(*dst, *curr_len); 985 *dst = realloc(*dst, *curr_len);

Legend:
Removed from v.1.68  
changed lines
  Added in v.1.69

  ViewVC Help
Powered by ViewVC 1.1.20