/[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.128 Revision 1.129
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.128 2006/02/17 15:36:16 solar Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.129 2006/02/18 15:51:11 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.128 2006/02/17 15:36:16 solar Exp $"; 12static const char *rcsid = "$Id: scanelf.c,v 1.129 2006/02/18 15:51:11 solar 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
116 continue; \ 116 continue; \
117 if (fix_elf && setpax) { \ 117 if (fix_elf && setpax) { \
118 /* set the paxctl flags */ \ 118 /* set the paxctl flags */ \
119 ESET(phdr[i].p_flags, setpax); \ 119 ESET(phdr[i].p_flags, setpax); \
120 } \ 120 } \
121 if (be_quiet && (EGET(phdr[i].p_flags) == 10240)) \ 121 if (be_quiet && (EGET(phdr[i].p_flags) == (PF_NOEMUTRAMP | PF_NORANDEXEC))) \
122 continue; \ 122 continue; \
123 memcpy(ret, pax_short_pf_flags(EGET(phdr[i].p_flags)), 6); \ 123 memcpy(ret, pax_short_pf_flags(EGET(phdr[i].p_flags)), 6); \
124 *found_pax = 1; \ 124 *found_pax = 1; \
125 ++shown; \ 125 ++shown; \
126 break; \ 126 break; \
131 } 131 }
132 132
133 133
134 if (fix_elf && setpax) { 134 if (fix_elf && setpax) {
135 /* set the chpax settings */ 135 /* set the chpax settings */
136 if (elf->elf_class == ELFCLASS32) 136 if (elf->elf_class == ELFCLASS32) {
137 if (EHDR32(elf->ehdr)->e_type == ET_DYN || EHDR32(elf->ehdr)->e_type == ET_EXEC)
137 ESET(EHDR32(elf->ehdr)->e_ident[EI_PAX], pax_pf2hf_flags(setpax)); 138 ESET(EHDR32(elf->ehdr)->e_ident[EI_PAX], pax_pf2hf_flags(setpax));
138 else 139 } else {
140 if (EHDR64(elf->ehdr)->e_type == ET_DYN || EHDR64(elf->ehdr)->e_type == ET_EXEC)
139 ESET(EHDR64(elf->ehdr)->e_ident[EI_PAX], pax_pf2hf_flags(setpax)); 141 ESET(EHDR64(elf->ehdr)->e_ident[EI_PAX], pax_pf2hf_flags(setpax));
142 }
140 } 143 }
141 144
142 /* fall back to EI_PAX if no PT_PAX was found */ 145 /* fall back to EI_PAX if no PT_PAX was found */
143 if (!*ret) { 146 if (!*ret) {
144 static char *paxflags; 147 static char *paxflags;
1087 strncpy(sbuf, match_etypes, sizeof(sbuf)); 1090 strncpy(sbuf, match_etypes, sizeof(sbuf));
1088 if (strchr(match_etypes, ',') != NULL) { 1091 if (strchr(match_etypes, ',') != NULL) {
1089 char *p; 1092 char *p;
1090 while((p = strrchr(sbuf, ',')) != NULL) { 1093 while((p = strrchr(sbuf, ',')) != NULL) {
1091 *p = 0; 1094 *p = 0;
1092 if (atoi(p+1) == get_etype(elf)) 1095 if (etype_lookup(p+1) == get_etype(elf))
1093 goto label_ret; 1096 goto label_ret;
1094 } 1097 }
1095 } 1098 }
1096 if (atoi(sbuf) != get_etype(elf)) 1099 if (etype_lookup(sbuf) != get_etype(elf))
1097 goto label_done; 1100 goto label_done;
1098 } 1101 }
1099 1102
1100label_ret: 1103label_ret:
1101 ret = scanelf_elfobj(elf); 1104 ret = scanelf_elfobj(elf);
1251 *p = 0; 1254 *p = 0;
1252 if ((p = strchr(path, '\n')) != NULL) 1255 if ((p = strchr(path, '\n')) != NULL)
1253 *p = 0; 1256 *p = 0;
1254#ifdef HAVE_GLOB 1257#ifdef HAVE_GLOB
1255 // recursive includes of the same file will make this segfault. 1258 // recursive includes of the same file will make this segfault.
1256 if ((*path == 'i') && (strncmp(path, "include", 7) == 0) && isblank(path[7])) { 1259 if ((memcmp(path, "include", 7) == 0) && isblank(path[7])) {
1257 glob64_t gl; 1260 glob64_t gl;
1258 size_t x; 1261 size_t x;
1259 char gpath[__PAX_UTILS_PATH_MAX]; 1262 char gpath[__PAX_UTILS_PATH_MAX];
1260 1263
1261 gpath[sizeof(gpath)] = 0; 1264 memset(gpath, 0, sizeof(gpath));
1262 1265
1263 if (path[8] != '/') 1266 if (path[8] != '/')
1264 snprintf(gpath, sizeof(gpath)-1, "/etc/%s", &path[8]); 1267 snprintf(gpath, sizeof(gpath), "/etc/%s", &path[8]);
1265 else 1268 else
1266 strncpy(gpath, &path[8], sizeof(gpath)-1); 1269 strncpy(gpath, &path[8], sizeof(gpath));
1267 1270
1268 if ((glob64(gpath, 0, NULL, &gl)) == 0) { 1271 if ((glob64(gpath, 0, NULL, &gl)) == 0) {
1269 for (x = 0; x < gl.gl_pathc; ++x) { 1272 for (x = 0; x < gl.gl_pathc; ++x) {
1270 /* try to avoid direct loops */ 1273 /* try to avoid direct loops */
1271 if (strcmp(gl.gl_pathv[x], fname) == 0) 1274 if (strcmp(gl.gl_pathv[x], fname) == 0)
1399 "Find a specified symbol", 1402 "Find a specified symbol",
1400 "Find a specified section", 1403 "Find a specified section",
1401 "Find a specified library", 1404 "Find a specified library",
1402 "Use strncmp to match libraries. (use with -N)", 1405 "Use strncmp to match libraries. (use with -N)",
1403 "Locate cause of TEXTREL", 1406 "Locate cause of TEXTREL",
1404 "Print only ELF files matching numeric constant type", 1407 "Print only ELF files matching etype ET_DYN,ET_EXEC ...",
1405 "Print only ELF files matching numeric bits", 1408 "Print only ELF files matching numeric bits",
1406 "Print all scanned info (-x -e -t -r -b)\n", 1409 "Print all scanned info (-x -e -t -r -b)\n",
1407 "Only output 'bad' things", 1410 "Only output 'bad' things",
1408 "Be verbose (can be specified more than once)", 1411 "Be verbose (can be specified more than once)",
1409 "Use specified format for output", 1412 "Use specified format for output",
1504 if (out_format) warn("You prob don't want to specify -F twice"); 1507 if (out_format) warn("You prob don't want to specify -F twice");
1505 out_format = optarg; 1508 out_format = optarg;
1506 break; 1509 break;
1507 } 1510 }
1508 case 'z': { 1511 case 'z': {
1509 unsigned long flags = 10240; 1512 unsigned long flags = (PF_NOEMUTRAMP | PF_NORANDEXEC);
1510 size_t x; 1513 size_t x;
1511 1514
1512#define do_state(option, flag) \ 1515#define do_state(option, flag) \
1513 if (islower(option)) { \ 1516 if (islower(option)) { \
1514 flags &= ~PF_##flag; \ 1517 flags &= ~PF_##flag; \

Legend:
Removed from v.1.128  
changed lines
  Added in v.1.129

  ViewVC Help
Powered by ViewVC 1.1.20