1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

gencache: Refactor gencache_set_data_blob

Replace 3 calls into talloc with 1. Add an overflow check.

With this change, it will be easier to avoid the talloc call for small
blobs in the future and do it on the stack.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Volker Lendecke 2015-12-13 21:16:36 +01:00 committed by Jeremy Allison
parent 640870ee20
commit 8ca3a58ec9

View File

@ -283,6 +283,8 @@ bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob,
time_t timeout)
{
int ret;
fstring hdr;
int hdr_len;
char* val;
time_t last_stabilize;
static int writecount;
@ -307,19 +309,23 @@ bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob,
return true;
}
val = talloc_asprintf(talloc_tos(), CACHE_DATA_FMT, (int)timeout);
if (val == NULL) {
return false;
}
val = talloc_realloc(NULL, val, char, talloc_array_length(val)-1);
if (val == NULL) {
return false;
}
val = (char *)talloc_append_blob(NULL, val, *blob);
hdr_len = fstr_sprintf(hdr, CACHE_DATA_FMT, (int)timeout);
if (hdr_len == -1) {
return false;
}
if ((blob->length + (size_t)hdr_len) < blob->length) {
return false;
}
val = talloc_array(talloc_tos(), char, hdr_len + blob->length);
if (val == NULL) {
return false;
}
memcpy(val, hdr, hdr_len);
memcpy(val+hdr_len, blob->data, blob->length);
DEBUG(10, ("Adding cache entry with key=[%s] and timeout="
"[%s] (%d seconds %s)\n", keystr,
timestring(talloc_tos(), timeout),