From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id DF178139082 for ; Wed, 29 Nov 2017 15:21:08 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1B5C1E0BE5; Wed, 29 Nov 2017 15:21:08 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id DDDCEE0BE5 for ; Wed, 29 Nov 2017 15:21:07 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 8906833BE2E for ; Wed, 29 Nov 2017 15:21:06 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 247CAABAE for ; Wed, 29 Nov 2017 15:21:05 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1511968667.d469b099b5e8aed45ff2edf78f91822b805440d3.grobian@gentoo> Subject: [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/files/ X-VCS-Repository: repo/proj/prefix X-VCS-Files: sys-devel/binutils-config/files/ldwrapper.c X-VCS-Directories: sys-devel/binutils-config/files/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: d469b099b5e8aed45ff2edf78f91822b805440d3 X-VCS-Branch: master Date: Wed, 29 Nov 2017 15:21:05 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: d9b55c64-3e0a-4f90-b033-d3371e0ad489 X-Archives-Hash: 663c7ea11a5f794d75f97cc6747bdbd3 commit: d469b099b5e8aed45ff2edf78f91822b805440d3 Author: Fabian Groffen gentoo org> AuthorDate: Wed Nov 29 15:17:47 2017 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Wed Nov 29 15:17:47 2017 +0000 URL: https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=d469b099 sys-devel/binutils-config: fix returned buffer from find_real_ld, bug #639172 Package-Manager: Portage-2.3.13-prefix, Repoman-2.3.4 sys-devel/binutils-config/files/ldwrapper.c | 35 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/sys-devel/binutils-config/files/ldwrapper.c b/sys-devel/binutils-config/files/ldwrapper.c index 88f93a8602..80831a7142 100644 --- a/sys-devel/binutils-config/files/ldwrapper.c +++ b/sys-devel/binutils-config/files/ldwrapper.c @@ -45,8 +45,8 @@ find_real_ld(char **ld, char verbose, char *wrapper) FILE *f = NULL; char *ldoveride; char *path; -#define ESIZ 1024 - char e[ESIZ]; +#define ESIZ 1024 /* POSIX_MAX_PATH */ + char *ret; struct stat lde; /* we may not succeed finding the linker */ @@ -65,6 +65,10 @@ find_real_ld(char **ld, char verbose, char *wrapper) fprintf(stdout, "%s: BINUTILS_CONFIG_LD not found in environment\n", wrapper); + ret = malloc(sizeof(char) * ESIZ); + if (ret == NULL) + return; + /* find ld in PATH, allowing easy PATH overrides */ path = getenv("PATH"); while (path > (char*)1 && *path != '\0') { @@ -72,9 +76,9 @@ find_real_ld(char **ld, char verbose, char *wrapper) if (q) *q = '\0'; if (strstr(path, "/" CHOST "/binutils-bin/") != NULL) { - snprintf(e, ESIZ, "%s/%s", path, wrapper); - if (stat(e, &lde) == 0) - *ld = e; + snprintf(ret, ESIZ, "%s/%s", path, wrapper); + if (stat(ret, &lde) == 0) + *ld = ret; } if (q) *q = ':'; /* restore PATH value */ @@ -88,7 +92,7 @@ find_real_ld(char **ld, char verbose, char *wrapper) /* parse EPREFIX/etc/env.d/binutils/config-CHOST to get CURRENT, then * consider $EPREFIX/usr/CHOST/binutils-bin/CURRENT where we should * be able to find ld */ - e[0] = '\0'; + ret[0] = '\0'; if ((f = fopen(EPREFIX "/etc/env.d/binutils/config-" CHOST, "r")) != NULL) { char p[ESIZ]; while (fgets(p, ESIZ, f) != NULL) { @@ -99,25 +103,25 @@ find_real_ld(char **ld, char verbose, char *wrapper) for (q--; isspace(*q); q--) *q = '\0'; ; - snprintf(e, ESIZ, EPREFIX "/usr/" CHOST "/binutils-bin/%s/%s", + snprintf(ret, ESIZ, EPREFIX "/usr/" CHOST "/binutils-bin/%s/%s", p + strlen("CURRENT="), wrapper); break; } } fclose(f); - if (stat(e, &lde) == 0) { - *ld = e; + if (stat(ret, &lde) == 0) { + *ld = ret; return; } } if (verbose) fprintf(stdout, "%s: linker not found via " EPREFIX "/etc/env.d/binutils/config-" CHOST " (ld=%s)\n", - wrapper, e); + wrapper, ret); /* last try, call binutils-config to tell us what the linker is * supposed to be */ - e[0] = '\0'; + ret[0] = '\0'; if ((f = popen("binutils-config -c", "r")) != NULL) { char p[ESIZ]; char *q; @@ -125,20 +129,21 @@ find_real_ld(char **ld, char verbose, char *wrapper) q = p; if (strncmp(q, CHOST "-", strlen(CHOST "-")) == 0) q += strlen(CHOST "-"); - snprintf(e, ESIZ, EPREFIX "/usr/" CHOST "/binutils-bin/%s/%s", + snprintf(ret, ESIZ, EPREFIX "/usr/" CHOST "/binutils-bin/%s/%s", q, wrapper); } else { *p = '\0'; } fclose(f); - if (*p && stat(e, &lde) == 0) { - *ld = e; + if (*p && stat(ret, &lde) == 0) { + *ld = ret; return; } } if (verbose) fprintf(stdout, "%s: linker not found via binutils-config -c (ld=%s)\n", - wrapper, e); + wrapper, ret); + free(ret); } int