| 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.99 2006/01/10 01:35:06 vapier Exp $ |
4 | * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.100 2006/01/10 01:38:17 vapier 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 | |
| 12 | static const char *rcsid = "$Id: scanelf.c,v 1.99 2006/01/10 01:35:06 vapier Exp $"; |
12 | static const char *rcsid = "$Id: scanelf.c,v 1.100 2006/01/10 01:38:17 vapier Exp $"; |
| 13 | #define argv0 "scanelf" |
13 | #define argv0 "scanelf" |
| 14 | |
14 | |
| 15 | #define IS_MODIFIER(c) (c == '%' || c == '#') |
15 | #define IS_MODIFIER(c) (c == '%' || c == '#') |
| 16 | |
16 | |
| 17 | |
17 | |
| … | |
… | |
| 356 | |
356 | |
| 357 | return NULL; |
357 | return NULL; |
| 358 | } |
358 | } |
| 359 | |
359 | |
| 360 | static void rpath_security_checks(elfobj *, char *); |
360 | static void rpath_security_checks(elfobj *, char *); |
| 361 | static void rpath_security_checks(elfobj *elf, char *item) { |
361 | static void rpath_security_checks(elfobj *elf, char *item) |
|
|
362 | { |
| 362 | struct stat st; |
363 | struct stat st; |
| 363 | switch (*item) { |
364 | switch (*item) { |
| 364 | case '/': break; |
365 | case '/': break; |
| 365 | case '.': |
366 | case '.': |
| 366 | warnf("Security problem with relative RPATH '%s' in %s", item, elf->filename); |
367 | warnf("Security problem with relative RPATH '%s' in %s", item, elf->filename); |
| 367 | break; |
368 | break; |
|
|
369 | case ':': |
| 368 | case '\0': |
370 | case '\0': |
| 369 | warnf("Security problem NULL RPATH in %s", elf->filename); |
371 | warnf("Security problem NULL RPATH in %s", elf->filename); |
| 370 | break; |
372 | break; |
| 371 | case '$': |
373 | case '$': |
| 372 | if (fstat(elf->fd, &st) != -1) |
374 | if (fstat(elf->fd, &st) != -1) |
| … | |
… | |
| 437 | if (!strncmp(ldpaths[s], start, len) && !ldpaths[s][len]) { \ |
439 | if (!strncmp(ldpaths[s], start, len) && !ldpaths[s][len]) { \ |
| 438 | *r = (end ? end + 1 : NULL); \ |
440 | *r = (end ? end + 1 : NULL); \ |
| 439 | break; \ |
441 | break; \ |
| 440 | } \ |
442 | } \ |
| 441 | } \ |
443 | } \ |
| 442 | if (!*r || !ldpaths[s] || !end) \ |
444 | if (!*r || !end) \ |
| 443 | start = NULL; \ |
445 | break; \ |
| 444 | else \ |
446 | else \ |
| 445 | start = start + len + 1; \ |
447 | start = start + len + 1; \ |
| 446 | } \ |
448 | } \ |
| 447 | } \ |
449 | } \ |
| 448 | if (*r) *found_rpath = 1; \ |
450 | if (*r) *found_rpath = 1; \ |
| … | |
… | |
| 1216 | VERSION, __FILE__, __DATE__, rcsid, argv0); |
1218 | VERSION, __FILE__, __DATE__, rcsid, argv0); |
| 1217 | exit(EXIT_SUCCESS); |
1219 | exit(EXIT_SUCCESS); |
| 1218 | break; |
1220 | break; |
| 1219 | case 'h': usage(EXIT_SUCCESS); break; |
1221 | case 'h': usage(EXIT_SUCCESS); break; |
| 1220 | case 'f': |
1222 | case 'f': |
| 1221 | if (from_file) err("Don't specify -f twice"); |
1223 | if (from_file) warn("You prob don't want to specify -f twice"); |
| 1222 | from_file = xstrdup(optarg); |
1224 | from_file = optarg; |
| 1223 | break; |
1225 | break; |
| 1224 | case 'o': { |
1226 | case 'o': { |
| 1225 | FILE *fp = NULL; |
1227 | FILE *fp = NULL; |
| 1226 | if ((fp = freopen(optarg, "w", stdout)) == NULL) |
1228 | if ((fp = freopen(optarg, "w", stdout)) == NULL) |
| 1227 | err("Could not open output stream '%s': %s", optarg, strerror(errno)); |
1229 | err("Could not open output stream '%s': %s", optarg, strerror(errno)); |
| … | |
… | |
| 1335 | load_ld_so_conf(); |
1337 | load_ld_so_conf(); |
| 1336 | if (scan_ldpath) scanelf_ldpath(); |
1338 | if (scan_ldpath) scanelf_ldpath(); |
| 1337 | if (scan_envpath) scanelf_envpath(); |
1339 | if (scan_envpath) scanelf_envpath(); |
| 1338 | if (from_file) { |
1340 | if (from_file) { |
| 1339 | scanelf_from_file(from_file); |
1341 | scanelf_from_file(from_file); |
| 1340 | free(from_file); |
|
|
| 1341 | from_file = *argv; |
1342 | from_file = *argv; |
| 1342 | } |
1343 | } |
| 1343 | if (optind == argc && !scan_ldpath && !scan_envpath && !from_file) |
1344 | if (optind == argc && !scan_ldpath && !scan_envpath && !from_file) |
| 1344 | err("Nothing to scan !?"); |
1345 | err("Nothing to scan !?"); |
| 1345 | while (optind < argc) { |
1346 | while (optind < argc) { |