Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/
Date: Wed, 29 Nov 2017 15:21:08
Message-Id: 1511968667.d469b099b5e8aed45ff2edf78f91822b805440d3.grobian@gentoo
1 commit: d469b099b5e8aed45ff2edf78f91822b805440d3
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Wed Nov 29 15:17:47 2017 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Wed Nov 29 15:17:47 2017 +0000
6 URL: https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=d469b099
7
8 sys-devel/binutils-config: fix returned buffer from find_real_ld, bug #639172
9
10 Package-Manager: Portage-2.3.13-prefix, Repoman-2.3.4
11
12 sys-devel/binutils-config/files/ldwrapper.c | 35 ++++++++++++++++-------------
13 1 file changed, 20 insertions(+), 15 deletions(-)
14
15 diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c
16 index 88f93a8602..80831a7142 100644
17 --- a/sys-devel/binutils-config/files/ldwrapper.c
18 +++ b/sys-devel/binutils-config/files/ldwrapper.c
19 @@ -45,8 +45,8 @@ find_real_ld(char **ld, char verbose, char *wrapper)
20 FILE *f = NULL;
21 char *ldoveride;
22 char *path;
23 -#define ESIZ 1024
24 - char e[ESIZ];
25 +#define ESIZ 1024 /* POSIX_MAX_PATH */
26 + char *ret;
27 struct stat lde;
28
29 /* we may not succeed finding the linker */
30 @@ -65,6 +65,10 @@ find_real_ld(char **ld, char verbose, char *wrapper)
31 fprintf(stdout, "%s: BINUTILS_CONFIG_LD not found in environment\n",
32 wrapper);
33
34 + ret = malloc(sizeof(char) * ESIZ);
35 + if (ret == NULL)
36 + return;
37 +
38 /* find ld in PATH, allowing easy PATH overrides */
39 path = getenv("PATH");
40 while (path > (char*)1 && *path != '\0') {
41 @@ -72,9 +76,9 @@ find_real_ld(char **ld, char verbose, char *wrapper)
42 if (q)
43 *q = '\0';
44 if (strstr(path, "/" CHOST "/binutils-bin/") != NULL) {
45 - snprintf(e, ESIZ, "%s/%s", path, wrapper);
46 - if (stat(e, &lde) == 0)
47 - *ld = e;
48 + snprintf(ret, ESIZ, "%s/%s", path, wrapper);
49 + if (stat(ret, &lde) == 0)
50 + *ld = ret;
51 }
52 if (q)
53 *q = ':'; /* restore PATH value */
54 @@ -88,7 +92,7 @@ find_real_ld(char **ld, char verbose, char *wrapper)
55 /* parse EPREFIX/etc/env.d/binutils/config-CHOST to get CURRENT, then
56 * consider $EPREFIX/usr/CHOST/binutils-bin/CURRENT where we should
57 * be able to find ld */
58 - e[0] = '\0';
59 + ret[0] = '\0';
60 if ((f = fopen(EPREFIX "/etc/env.d/binutils/config-" CHOST, "r")) != NULL) {
61 char p[ESIZ];
62 while (fgets(p, ESIZ, f) != NULL) {
63 @@ -99,25 +103,25 @@ find_real_ld(char **ld, char verbose, char *wrapper)
64 for (q--; isspace(*q); q--)
65 *q = '\0';
66 ;
67 - snprintf(e, ESIZ, EPREFIX "/usr/" CHOST "/binutils-bin/%s/%s",
68 + snprintf(ret, ESIZ, EPREFIX "/usr/" CHOST "/binutils-bin/%s/%s",
69 p + strlen("CURRENT="), wrapper);
70 break;
71 }
72 }
73 fclose(f);
74 - if (stat(e, &lde) == 0) {
75 - *ld = e;
76 + if (stat(ret, &lde) == 0) {
77 + *ld = ret;
78 return;
79 }
80 }
81 if (verbose)
82 fprintf(stdout, "%s: linker not found via " EPREFIX
83 "/etc/env.d/binutils/config-" CHOST " (ld=%s)\n",
84 - wrapper, e);
85 + wrapper, ret);
86
87 /* last try, call binutils-config to tell us what the linker is
88 * supposed to be */
89 - e[0] = '\0';
90 + ret[0] = '\0';
91 if ((f = popen("binutils-config -c", "r")) != NULL) {
92 char p[ESIZ];
93 char *q;
94 @@ -125,20 +129,21 @@ find_real_ld(char **ld, char verbose, char *wrapper)
95 q = p;
96 if (strncmp(q, CHOST "-", strlen(CHOST "-")) == 0)
97 q += strlen(CHOST "-");
98 - snprintf(e, ESIZ, EPREFIX "/usr/" CHOST "/binutils-bin/%s/%s",
99 + snprintf(ret, ESIZ, EPREFIX "/usr/" CHOST "/binutils-bin/%s/%s",
100 q, wrapper);
101 } else {
102 *p = '\0';
103 }
104 fclose(f);
105 - if (*p && stat(e, &lde) == 0) {
106 - *ld = e;
107 + if (*p && stat(ret, &lde) == 0) {
108 + *ld = ret;
109 return;
110 }
111 }
112 if (verbose)
113 fprintf(stdout, "%s: linker not found via binutils-config -c (ld=%s)\n",
114 - wrapper, e);
115 + wrapper, ret);
116 + free(ret);
117 }
118
119 int