1 |
vapier 11/10/03 03:43:31 |
2 |
|
3 |
Modified: prelink.c |
4 |
Log: |
5 |
filter out elfs by their type |
6 |
|
7 |
Revision Changes Path |
8 |
1.2 portage-utils/libq/prelink.c |
9 |
|
10 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/prelink.c?rev=1.2&view=markup |
11 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/prelink.c?rev=1.2&content-type=text/plain |
12 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/prelink.c?r1=1.1&r2=1.2 |
13 |
|
14 |
Index: prelink.c |
15 |
=================================================================== |
16 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/prelink.c,v |
17 |
retrieving revision 1.1 |
18 |
retrieving revision 1.2 |
19 |
diff -u -r1.1 -r1.2 |
20 |
--- prelink.c 3 Oct 2011 00:24:22 -0000 1.1 |
21 |
+++ prelink.c 3 Oct 2011 03:43:31 -0000 1.2 |
22 |
@@ -1,7 +1,7 @@ |
23 |
/* |
24 |
* Copyright 2011 Gentoo Foundation |
25 |
* Distributed under the terms of the GNU General Public License v2 |
26 |
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/prelink.c,v 1.1 2011/10/03 00:24:22 vapier Exp $ |
27 |
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/prelink.c,v 1.2 2011/10/03 03:43:31 vapier Exp $ |
28 |
*/ |
29 |
|
30 |
static const char prelink_bin[] = "prelink"; |
31 |
@@ -60,10 +60,11 @@ |
32 |
|
33 |
#ifdef __linux__ |
34 |
#include <elf.h> |
35 |
-static bool is_elf(int fd, const char *filename) |
36 |
+static bool is_prelink_elf(int fd, const char *filename) |
37 |
{ |
38 |
- char header[SELFMAG]; |
39 |
+ unsigned char header[EI_NIDENT + 2]; |
40 |
ssize_t len; |
41 |
+ uint16_t e_type; |
42 |
|
43 |
len = read(fd, &header, sizeof(header)); |
44 |
if (len == -1) { |
45 |
@@ -75,10 +76,32 @@ |
46 |
if (len < sizeof(header)) |
47 |
return false; |
48 |
|
49 |
- return memcmp(header, ELFMAG, sizeof(header)) == 0 ? true : false; |
50 |
+ if (memcmp(header, ELFMAG, SELFMAG)) |
51 |
+ return false; |
52 |
+ |
53 |
+ /* prelink only likes certain types of ELFs */ |
54 |
+ switch (header[EI_DATA]) { |
55 |
+ case ELFDATA2LSB: |
56 |
+ e_type = header[EI_NIDENT] | (header[EI_NIDENT + 1] << 8); |
57 |
+ break; |
58 |
+ case ELFDATA2MSB: |
59 |
+ e_type = header[EI_NIDENT + 1] | (header[EI_NIDENT] << 8); |
60 |
+ break; |
61 |
+ default: |
62 |
+ return false; |
63 |
+ } |
64 |
+ switch (e_type) { |
65 |
+ case ET_EXEC: |
66 |
+ case ET_DYN: |
67 |
+ return true; |
68 |
+ default: |
69 |
+ return false; |
70 |
+ } |
71 |
+ |
72 |
+ /* XXX: should we also check OS's/arches that prelink supports ? */ |
73 |
} |
74 |
#else |
75 |
-static bool is_elf(int fd, const char *filename) |
76 |
+static bool is_prelink_elf(int fd, const char *filename) |
77 |
{ |
78 |
return false; |
79 |
} |
80 |
@@ -93,7 +116,7 @@ |
81 |
{ |
82 |
int pipefd[2]; |
83 |
|
84 |
- if (!is_elf(fd, filename)) |
85 |
+ if (!is_prelink_elf(fd, filename)) |
86 |
return fd; |
87 |
|
88 |
if (pipe(pipefd)) |