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 F28DC1395E3 for ; Sat, 12 Nov 2016 07:15:40 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8CE6521C09E; Sat, 12 Nov 2016 07:15:38 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 7577D21C09E for ; Sat, 12 Nov 2016 07:15:38 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 81FBB341666 for ; Sat, 12 Nov 2016 07:15:36 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 497FC24BB for ; Sat, 12 Nov 2016 07:15:35 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1478934608.c2604c2b909f903efd1b2c924b380e81d8459ec9.vapier@gentoo> Subject: [gentoo-commits] proj/pax-utils:master commit in: / X-VCS-Repository: proj/pax-utils X-VCS-Files: paxldso.c X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: c2604c2b909f903efd1b2c924b380e81d8459ec9 X-VCS-Branch: master Date: Sat, 12 Nov 2016 07:15:35 +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: 5fff8f81-48b0-482e-9051-99fdfcc6485f X-Archives-Hash: 7b8466ceafad5b717b1366849220348f commit: c2604c2b909f903efd1b2c924b380e81d8459ec9 Author: Mike Frysinger gentoo org> AuthorDate: Mon Jul 25 08:19:44 2016 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Sat Nov 12 07:10:08 2016 +0000 URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=c2604c2b paxldso: switch from a static sized path buffer to dynamic We keep the buffer around to avoid the malloc overhead between calls, and we should really only need to grow it once or twice. This way we work with an sized lib path and not just the static limit. paxldso.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/paxldso.c b/paxldso.c index 67f317c..61d7962 100644 --- a/paxldso.c +++ b/paxldso.c @@ -17,6 +17,9 @@ static void *ldcache = NULL; static size_t ldcache_size = 0; +static char *ldso_cache_buf = NULL; +static size_t ldso_cache_buf_size = 0; + /* Defines can be seen in glibc's sysdeps/generic/ldconfig.h */ #define LDSO_CACHE_MAGIC "ld.so-" #define LDSO_CACHE_MAGIC_LEN (sizeof LDSO_CACHE_MAGIC -1) @@ -45,8 +48,8 @@ static size_t ldcache_size = 0; char *ldso_cache_lookup_lib(elfobj *elf, const char *fname) { int fd; + char *ret = NULL; char *strs; - static char buf[__PAX_UTILS_PATH_MAX] = ""; const char *cachefile = root_rel_path("/etc/ld.so.cache"); struct stat st; @@ -92,6 +95,9 @@ char *ldso_cache_lookup_lib(elfobj *elf, const char *fname) ldcache = NULL; return NULL; } + + ldso_cache_buf_size = 4096; + ldso_cache_buf = xrealloc(ldso_cache_buf, ldso_cache_buf_size); } else header = ldcache; @@ -99,6 +105,9 @@ char *ldso_cache_lookup_lib(elfobj *elf, const char *fname) strs = (char *) &libent[header->nlibs]; for (fd = 0; fd < header->nlibs; ++fd) { + const char *lib; + size_t lib_len; + /* This should be more fine grained, but for now we assume that * diff arches will not be cached together, and we ignore the * the different multilib mips cases. @@ -112,17 +121,26 @@ char *ldso_cache_lookup_lib(elfobj *elf, const char *fname) continue; /* Return first hit because that is how the ldso rolls */ - strncpy(buf, strs + libent[fd].liboffset, sizeof(buf)); + lib = strs + libent[fd].liboffset; + lib_len = strlen(lib) + 1; + if (lib_len > ldso_cache_buf_size) { + ldso_cache_buf = xrealloc(ldso_cache_buf, ldso_cache_buf_size + 4096); + ldso_cache_buf_size += 4096; + } + memcpy(ldso_cache_buf, lib, lib_len); + ret = ldso_cache_buf; break; } - return buf; + return ret; } #endif static void ldso_cache_cleanup(void) { + free(ldso_cache_buf); + if (ldcache != NULL) munmap(ldcache, ldcache_size); }