Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-projects commit in pax-utils: scanelf.c
Date: Tue, 27 Sep 2011 19:21:02
Message-Id: 20110927192052.03B5020036@flycatcher.gentoo.org
1 vapier 11/09/27 19:20:52
2
3 Modified: scanelf.c
4 Log:
5 convert ldpaths over to new array code to make it easier to maintain
6
7 Revision Changes Path
8 1.227 pax-utils/scanelf.c
9
10 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?rev=1.227&view=markup
11 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?rev=1.227&content-type=text/plain
12 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?r1=1.226&r2=1.227
13
14 Index: scanelf.c
15 ===================================================================
16 RCS file: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v
17 retrieving revision 1.226
18 retrieving revision 1.227
19 diff -u -r1.226 -r1.227
20 --- scanelf.c 27 Sep 2011 18:37:22 -0000 1.226
21 +++ scanelf.c 27 Sep 2011 19:20:51 -0000 1.227
22 @@ -1,13 +1,13 @@
23 /*
24 * Copyright 2003-2007 Gentoo Foundation
25 * Distributed under the terms of the GNU General Public License v2
26 - * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.226 2011/09/27 18:37:22 vapier Exp $
27 + * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.227 2011/09/27 19:20:51 vapier Exp $
28 *
29 * Copyright 2003-2007 Ned Ludd - <solar@g.o>
30 * Copyright 2004-2007 Mike Frysinger - <vapier@g.o>
31 */
32
33 -static const char *rcsid = "$Id: scanelf.c,v 1.226 2011/09/27 18:37:22 vapier Exp $";
34 +static const char *rcsid = "$Id: scanelf.c,v 1.227 2011/09/27 19:20:51 vapier Exp $";
35 const char argv0[] = "scanelf";
36
37 #include "paxinc.h"
38 @@ -30,7 +30,7 @@
39
40 /* variables to control behavior */
41 static char match_etypes[126] = "";
42 -static char *ldpaths[256];
43 +static array_t _ldpaths = array_init_decl, *ldpaths = &_ldpaths;
44 static char scan_ldpath = 0;
45 static char scan_envpath = 0;
46 static char scan_symlink = 1;
47 @@ -534,7 +534,7 @@
48 }
49 static void scanelf_file_rpath(elfobj *elf, char *found_rpath, char **ret, size_t *ret_len)
50 {
51 - unsigned long i, s;
52 + unsigned long i;
53 char *rpath, *runpath, **r;
54 void *strtbl_void;
55
56 @@ -589,9 +589,11 @@
57 rpath_security_checks(elf, start, get_elfdtype(word)); \
58 end = strchr(start, ':'); \
59 len = (end ? abs(end - start) : strlen(start)); \
60 - if (use_ldcache) \
61 - for (s = 0; ldpaths[s]; ++s) \
62 - if (!strncmp(ldpaths[s], start, len) && !ldpaths[s][len]) { \
63 + if (use_ldcache) { \
64 + size_t n; \
65 + const char *ldpath; \
66 + array_for_each(ldpaths, n, ldpath) \
67 + if (!strncmp(ldpath, start, len) && !ldpath[len]) { \
68 *r = end; \
69 /* corner case ... if RPATH reads "/usr/lib:", we want \
70 * to show ':' rather than '' */ \
71 @@ -599,6 +601,7 @@
72 (*r)++; \
73 break; \
74 } \
75 + } \
76 if (!*r || !end) \
77 break; \
78 else \
79 @@ -779,10 +782,11 @@
80 {
81 static char buf[__PAX_UTILS_PATH_MAX] = "";
82 static struct stat st;
83 + size_t n;
84 + char *ldpath;
85
86 - char **ldpath;
87 - for (ldpath = ldpaths; *ldpath != NULL; ldpath++) {
88 - if ((unsigned) snprintf(buf, sizeof(buf), "%s/%s", *ldpath, fname) >= sizeof(buf))
89 + array_for_each(ldpath, n, ldpath) {
90 + if ((unsigned) snprintf(buf, sizeof(buf), "%s/%s", ldpath, fname) >= sizeof(buf))
91 continue; /* if the pathname is too long, or something went wrong, ignore */
92
93 if (stat(buf, &st) != 0)
94 @@ -1627,9 +1631,6 @@
95
96 fname = maybe_add_root(fname, _fname);
97
98 - if (i + 1 == ARRAY_SIZE(ldpaths))
99 - return i;
100 -
101 if ((fp = fopen(fname, "r")) == NULL)
102 return i;
103
104 @@ -1660,10 +1661,6 @@
105 if (strcmp(gl.gl_pathv[x], fname) == 0)
106 continue;
107 i = load_ld_cache_config(i, gl.gl_pathv[x]);
108 - if (i + 1 >= ARRAY_SIZE(ldpaths)) {
109 - globfree(&gl);
110 - return i;
111 - }
112 }
113 globfree(&gl);
114 continue;
115 @@ -1673,12 +1670,8 @@
116 if (*path != '/')
117 continue;
118
119 - ldpaths[i++] = xstrdup(path);
120 -
121 - if (i + 1 == ARRAY_SIZE(ldpaths))
122 - break;
123 + xarraypush(ldpaths, path, strlen(path));
124 }
125 - ldpaths[i] = NULL;
126
127 fclose(fp);
128 return i;
129 @@ -1695,9 +1688,6 @@
130
131 fname = maybe_add_root(fname, _fname);
132
133 - if (i + 1 == ARRAY_SIZE(ldpaths))
134 - return i;
135 -
136 if ((fp = fopen(fname, "r")) == NULL)
137 return i;
138
139 @@ -1717,13 +1707,10 @@
140 }
141
142 while ((p = strsep(&b, ":"))) {
143 - if (*p == '\0') continue;
144 - ldpaths[i++] = xstrdup(p);
145 -
146 - if (i + 1 == ARRAY_SIZE(ldpaths))
147 - break;
148 + if (*p == '\0')
149 + continue;
150 + xarraypush(ldpaths, p, strlen(p));
151 }
152 - ldpaths[i] = NULL;
153
154 free(b);
155 fclose(fp);
156 @@ -1736,7 +1723,6 @@
157 #endif
158 static int load_ld_cache_config(int i, const char *fname)
159 {
160 - memset(ldpaths, 0x00, sizeof(ldpaths));
161 return 0;
162 }
163 #endif
164 @@ -1745,18 +1731,20 @@
165 static void scanelf_ldpath(void)
166 {
167 char scan_l, scan_ul, scan_ull;
168 + size_t n;
169 + const char *ldpath;
170 int i = 0;
171
172 - if (!ldpaths[0])
173 + if (array_cnt(ldpaths) == 0)
174 err("Unable to load any paths from ld.so.conf");
175
176 scan_l = scan_ul = scan_ull = 0;
177
178 - while (ldpaths[i]) {
179 - if (!scan_l && !strcmp(ldpaths[i], "/lib")) scan_l = 1;
180 - if (!scan_ul && !strcmp(ldpaths[i], "/usr/lib")) scan_ul = 1;
181 - if (!scan_ull && !strcmp(ldpaths[i], "/usr/local/lib")) scan_ull = 1;
182 - scanelf_dir(ldpaths[i]);
183 + array_for_each(ldpaths, n, ldpath) {
184 + if (!scan_l && !strcmp(ldpath, "/lib")) scan_l = 1;
185 + if (!scan_ul && !strcmp(ldpath, "/usr/lib")) scan_ul = 1;
186 + if (!scan_ull && !strcmp(ldpath, "/usr/local/lib")) scan_ull = 1;
187 + scanelf_dir(ldpath);
188 ++i;
189 }
190
191 @@ -2141,8 +2129,9 @@
192 }
193
194 /* clean up */
195 - for (i = 0; ldpaths[i]; ++i)
196 - free(ldpaths[i]);
197 + xarrayfree(ldpaths);
198 + xarrayfree(find_lib_arr);
199 + xarrayfree(find_section_arr);
200 free(find_lib);
201 free(find_section);