Bound stream path allocations and validate wire rejection cases
This commit is contained in:
1 parent
fc80186043
commit
0b202bb3e7
3 files changed
+53
-6
No files matched your search
@@ -6,10 +6,12 @@
|
||||
|
||||
#define STREAM_SLOT_NONE UINT32_MAX
|
||||
|
||||
struct stream_cached_path { uint8_t count; uint64_t nodes[]; };
|
||||
|
||||
struct stream_cached_slot {
|
||||
uint32_t next;
|
||||
uint8_t subblock;
|
||||
struct stream_path *path; /* NULL — исходный путь {source}, без отдельной аллокации. */
|
||||
struct stream_cached_path *path; /* NULL — исходный путь {source}, без отдельной аллокации. */
|
||||
};
|
||||
|
||||
struct stream_cached_batch {
|
||||
@@ -227,12 +229,12 @@ int stream_buffer_put_path(struct stream_buffer *b, const uint8_t *wire, size_t
|
||||
(unsigned long long)view.seq, view.subblock, (unsigned long long)b->heap[0]->seq);
|
||||
return STREAM_EXPIRED;
|
||||
}
|
||||
struct stream_path *stored_path = path->count > 1 ? u_malloc(sizeof(*stored_path)) : NULL;
|
||||
struct stream_cached_path *stored_path = path->count > 1 ? u_malloc(sizeof(*stored_path) + path->count * 8u) : NULL;
|
||||
if (path->count > 1 && !stored_path) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_STREAM, "buffer path allocation failed seq=%llu", (unsigned long long)view.seq);
|
||||
return STREAM_ERR_MEMORY;
|
||||
}
|
||||
if (stored_path) *stored_path = *path;
|
||||
if (stored_path) { stored_path->count = path->count; memcpy(stored_path->nodes, path->nodes, path->count * 8u); }
|
||||
int new_batch = batch == NULL;
|
||||
if (new_batch) {
|
||||
batch = u_calloc(1, sizeof(*batch));
|
||||
@@ -276,7 +278,11 @@ int stream_buffer_path(struct stream_buffer *b, uint64_t seq, uint8_t subblock,
|
||||
struct stream_cached_batch *batch = buffer_batch(b, seq);
|
||||
uint32_t slot = batch ? buffer_slot(b, batch, subblock) : STREAM_SLOT_NONE;
|
||||
if (slot == STREAM_SLOT_NONE) return seq < b->stats.expired_before ? STREAM_EXPIRED : STREAM_GAP;
|
||||
*path = b->slots[slot].path ? *b->slots[slot].path : (struct stream_path){.nodes = {b->descriptor.source_node_id}, .count = 1};
|
||||
*path = (struct stream_path){.nodes = {b->descriptor.source_node_id}, .count = 1};
|
||||
if (b->slots[slot].path) {
|
||||
path->count = b->slots[slot].path->count;
|
||||
memcpy(path->nodes, b->slots[slot].path->nodes, path->count * 8u);
|
||||
}
|
||||
return STREAM_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user