1 |
commit: c1a7c3366024334c97303cad6e1e54e30285beda |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Dec 30 09:16:03 2019 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Dec 30 09:16:03 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=c1a7c336 |
7 |
|
8 |
libq/tree: ensure valid pointers in case of realloc |
9 |
|
10 |
in tree_read_file_binpkg_xpak_cb pointers could get stale after realloc, |
11 |
if so, reposition them in the newly allocated block |
12 |
|
13 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
14 |
|
15 |
libq/tree.c | 10 ++++++++++ |
16 |
1 file changed, 10 insertions(+) |
17 |
|
18 |
diff --git a/libq/tree.c b/libq/tree.c |
19 |
index f0c8ddb..d9eec76 100644 |
20 |
--- a/libq/tree.c |
21 |
+++ b/libq/tree.c |
22 |
@@ -876,9 +876,19 @@ tree_read_file_binpkg_xpak_cb( |
23 |
data_len--; |
24 |
|
25 |
if (len - pos < (size_t)data_len) { |
26 |
+ char *old_data = m->_data; |
27 |
len += (((data_len + 1) / BUFSIZ) + 1) * BUFSIZ; |
28 |
m->_data = xrealloc(m->_data, len); |
29 |
m->_md5_ = (char *)len; |
30 |
+ |
31 |
+ /* re-position existing keys */ |
32 |
+ if (old_data != NULL && m->_data != old_data) { |
33 |
+ char **newdata = (char **)m; |
34 |
+ int elems = sizeof(tree_pkg_meta) / sizeof(char *); |
35 |
+ while (elems-- > 0) |
36 |
+ if (newdata[elems] != NULL) |
37 |
+ newdata[elems] = m->_data + (newdata[elems] - old_data); |
38 |
+ } |
39 |
} |
40 |
|
41 |
*key = m->_data + pos; |