From 6f2fdbc28eac5f1aa8819242c6506bc3bffb7ebe Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Wed, 6 Mar 2013 15:42:26 +0100 Subject: fix dataiterator returning random data in some cases Fixed two issues: 1) iterating over attributes in with vertical storage could return junk when some other operation paged in some other data. 2) the returned string could also be in the paged area, or also in tmpspace if stringification was done. We can't simply alloc memory as this makes things slower, but in most cases the storage does not matter. So we offer a new function, dataiterator_strdup(), that makes the kv.str pointer persistent. WARNING: this commit is an ABI change as it changes the dataiterator structure. Sorry. --- src/repopack.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/repopack.h') diff --git a/src/repopack.h b/src/repopack.h index 81b7b88..d75e61a 100644 --- a/src/repopack.h +++ b/src/repopack.h @@ -164,12 +164,15 @@ data_fetch(unsigned char *dp, KeyValue *kv, Repokey *key) kv->num2 = 0; return data_read_u32(dp, &kv->num); case REPOKEY_TYPE_MD5: + kv->num = 0; /* not stringified yet */ kv->str = (const char *)dp; return dp + SIZEOF_MD5; case REPOKEY_TYPE_SHA1: + kv->num = 0; /* not stringified yet */ kv->str = (const char *)dp; return dp + SIZEOF_SHA1; case REPOKEY_TYPE_SHA256: + kv->num = 0; /* not stringified yet */ kv->str = (const char *)dp; return dp + SIZEOF_SHA256; case REPOKEY_TYPE_BINARY: @@ -180,6 +183,7 @@ data_fetch(unsigned char *dp, KeyValue *kv, Repokey *key) return data_read_ideof(dp, &kv->id, &kv->eof); case REPOKEY_TYPE_DIRSTRARRAY: dp = data_read_ideof(dp, &kv->id, &kv->eof); + kv->num = 0; /* not stringified yet */ kv->str = (const char *)dp; return dp + strlen(kv->str) + 1; case REPOKEY_TYPE_DIRNUMNUMARRAY: -- cgit v1.2.3