Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/core/client_reqresp_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@ static void *block_request_worker(void *arg)
.peer = ctx->peer_text[0] ? ctx->peer_text : NULL,
};

LanternBlocksByRootRequest request;
lantern_blocks_by_root_request_init(&request);
uint8_t *raw_request = NULL;
uint8_t *payload = NULL;
enum lantern_blocks_request_outcome outcome = LANTERN_BLOCKS_REQUEST_FAILED;
bool completed = false;

char root_hex[(LANTERN_ROOT_SIZE * 2u) + 3u];
if (!ctx->roots || ctx->root_count == 0)
{
Expand All @@ -331,14 +338,6 @@ static void *block_request_worker(void *arg)
}
format_root_hex(&ctx->roots[0], root_hex, sizeof(root_hex));

LanternBlocksByRootRequest request;
lantern_blocks_by_root_request_init(&request);

uint8_t *raw_request = NULL;
uint8_t *payload = NULL;
enum lantern_blocks_request_outcome outcome = LANTERN_BLOCKS_REQUEST_FAILED;
bool completed = false;

if (lantern_root_list_resize(&request.roots, ctx->root_count) != 0)
{
lantern_log_error(
Expand Down
31 changes: 22 additions & 9 deletions src/internal/yaml_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,20 @@ static void add_pair(LanternYamlObject *obj, const char *key, const char *value)
obj->num_pairs++;
}

static void commit_current(
static int commit_current(
LanternYamlObject *current,
LanternYamlObject **objects,
size_t *capacity,
size_t *count) {
if (!current || current->num_pairs == 0) {
return;
return 0;
}

if (*count == *capacity) {
size_t new_capacity = (*capacity == 0) ? 4 : (*capacity * 2);
LanternYamlObject *new_objects = realloc(*objects, new_capacity * sizeof(*new_objects));
if (!new_objects) {
return;
return -1;
}
*objects = new_objects;
*capacity = new_capacity;
Expand All @@ -121,6 +121,7 @@ static void commit_current(
current->pairs = NULL;
current->num_pairs = 0;
current->capacity = 0;
return 0;
}

static void free_yaml_object(LanternYamlObject *object) {
Expand Down Expand Up @@ -172,7 +173,10 @@ LanternYamlObject *lantern_yaml_read_array(const char *file_path, const char *ar

if (content[0] == '-') {
if (in_target_array) {
commit_current(&current, &objects, &capacity, out_count);
if (commit_current(&current, &objects, &capacity, out_count) != 0) {
parse_error = 1;
break;
}
}
content++;
while (isspace((unsigned char)*content)) {
Expand All @@ -185,10 +189,16 @@ LanternYamlObject *lantern_yaml_read_array(const char *file_path, const char *ar
while (stack_size > 0 && indent_stack[stack_size - 1] >= indent) {
pop_stack(keys_stack, &stack_size);
if (in_target_array && stack_size < array_depth) {
commit_current(&current, &objects, &capacity, out_count);
if (commit_current(&current, &objects, &capacity, out_count) != 0) {
parse_error = 1;
break;
}
in_target_array = 0;
}
}
if (parse_error) {
break;
}
}

char *sep = strchr(content, ':');
Expand Down Expand Up @@ -244,6 +254,12 @@ LanternYamlObject *lantern_yaml_read_array(const char *file_path, const char *ar

fclose(fp);

if (!parse_error && in_target_array) {
if (commit_current(&current, &objects, &capacity, out_count) != 0) {
parse_error = 1;
}
}

if (parse_error) {
free_yaml_object(&current);
lantern_yaml_free_objects(objects, *out_count);
Expand All @@ -254,13 +270,10 @@ LanternYamlObject *lantern_yaml_read_array(const char *file_path, const char *ar
return NULL;
}

if (in_target_array) {
commit_current(&current, &objects, &capacity, out_count);
}

for (int i = 0; i < stack_size; ++i) {
free(keys_stack[i]);
}
free_yaml_object(&current);

if (*out_count == 0) {
free(objects);
Expand Down
8 changes: 4 additions & 4 deletions src/networking/enr.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,15 @@ int lantern_enr_record_decode(const char *enr_text, struct lantern_enr_record *r
return -1;
}

struct lantern_rlp_view root;
memset(&root, 0, sizeof(root));
int root_ready = 0;
uint8_t *encoded_bytes = NULL;
size_t encoded_len = 0;
if (lantern_base64url_decode(payload, &encoded_bytes, &encoded_len) != 0) {
goto error;
}

struct lantern_rlp_view root;
memset(&root, 0, sizeof(root));
int root_ready = 0;
if (lantern_rlp_decode(encoded_bytes, encoded_len, &root) != 0) {
goto error;
}
Expand Down Expand Up @@ -356,6 +356,7 @@ int lantern_enr_record_build_v4(
struct lantern_rlp_buffer signed_record = {0};
struct lantern_rlp_buffer content = {0};
struct lantern_rlp_buffer signature_buf = {0};
size_t idx = 0;

uint8_t ip_bytes[4];
if (parse_ipv4_address(ip_string, ip_bytes) != 0) {
Expand Down Expand Up @@ -390,7 +391,6 @@ int lantern_enr_record_build_v4(
}
secp256k1_context_destroy(ctx);

size_t idx = 0;
if (lantern_rlp_encode_uint64(&items[idx++], sequence) != 0) {
error_reason = "rlp encode sequence failed";
goto error;
Expand Down