summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2003-07-01 12:03:00 +0000
committerVolker Lendecke <vlendec@samba.org>2003-07-01 12:03:00 +0000
commitf036368efdcbe576552ea85a78e5e6199a2b2c6d (patch)
treef7366603a2bab43d86134b3c566e7f9b40663bc7
parent9d317fb533c5236bef1701d322abd537beea02d5 (diff)
downloadsamba-f036368efdcbe576552ea85a78e5e6199a2b2c6d.tar.gz
samba-f036368efdcbe576552ea85a78e5e6199a2b2c6d.tar.xz
samba-f036368efdcbe576552ea85a78e5e6199a2b2c6d.zip
Fix a segfault found by metze & valgrind...
Don't overwrite past the end of a string. Volker
-rw-r--r--source/lib/gencache.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/source/lib/gencache.c b/source/lib/gencache.c
index 58e44e3f0bb..f3740e3e127 100644
--- a/source/lib/gencache.c
+++ b/source/lib/gencache.c
@@ -319,9 +319,8 @@ void gencache_iterate(void (*fn)(const char* key, const char *value, time_t time
while (node) {
/* ensure null termination of the key string */
- node->node_key.dptr[node->node_key.dsize] = '\0';
- keystr = node->node_key.dptr;
-
+ keystr = strndup(node->node_key.dptr, node->node_key.dsize);
+
/*
* We don't use gencache_get function, because we need to iterate through
* all of the entries. Validity verification is up to fn routine.
@@ -329,6 +328,8 @@ void gencache_iterate(void (*fn)(const char* key, const char *value, time_t time
databuf = tdb_fetch(cache, node->node_key);
if (!databuf.dptr || databuf.dsize <= TIMEOUT_LEN) {
SAFE_FREE(databuf.dptr);
+ SAFE_FREE(keystr);
+ node = node->next;
continue;
}
entry = strndup(databuf.dptr, databuf.dsize);
@@ -342,6 +343,7 @@ void gencache_iterate(void (*fn)(const char* key, const char *value, time_t time
SAFE_FREE(valstr);
SAFE_FREE(entry);
+ SAFE_FREE(keystr);
node = node->next;
}