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 76323138334 for ; Mon, 30 Dec 2019 17:24:54 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8094DE0C8A; Mon, 30 Dec 2019 17:24:53 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (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 64C2EE0C8A for ; Mon, 30 Dec 2019 17:24:53 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (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 0C93734DD71 for ; Mon, 30 Dec 2019 17:24:52 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A1EC079 for ; Mon, 30 Dec 2019 17:24:49 +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: <1577697363.c1a7c3366024334c97303cad6e1e54e30285beda.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/ X-VCS-Repository: proj/portage-utils X-VCS-Files: libq/tree.c X-VCS-Directories: libq/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: c1a7c3366024334c97303cad6e1e54e30285beda X-VCS-Branch: master Date: Mon, 30 Dec 2019 17:24:49 +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-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 4c07e0e8-779a-4ebb-9ff9-45d87a9e3731 X-Archives-Hash: 3fb358c340d1ed07417ddb15b4d4756a commit: c1a7c3366024334c97303cad6e1e54e30285beda Author: Fabian Groffen gentoo org> AuthorDate: Mon Dec 30 09:16:03 2019 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Mon Dec 30 09:16:03 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=c1a7c336 libq/tree: ensure valid pointers in case of realloc in tree_read_file_binpkg_xpak_cb pointers could get stale after realloc, if so, reposition them in the newly allocated block Signed-off-by: Fabian Groffen gentoo.org> libq/tree.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libq/tree.c b/libq/tree.c index f0c8ddb..d9eec76 100644 --- a/libq/tree.c +++ b/libq/tree.c @@ -876,9 +876,19 @@ tree_read_file_binpkg_xpak_cb( data_len--; if (len - pos < (size_t)data_len) { + char *old_data = m->_data; len += (((data_len + 1) / BUFSIZ) + 1) * BUFSIZ; m->_data = xrealloc(m->_data, len); m->_md5_ = (char *)len; + + /* re-position existing keys */ + if (old_data != NULL && m->_data != old_data) { + char **newdata = (char **)m; + int elems = sizeof(tree_pkg_meta) / sizeof(char *); + while (elems-- > 0) + if (newdata[elems] != NULL) + newdata[elems] = m->_data + (newdata[elems] - old_data); + } } *key = m->_data + pos;