Skip to content

Commit

Permalink
Update nanopb submodule to release 0.4.7.
Browse files Browse the repository at this point in the history
Also fix some self-check code that broke due to the update.
Also update the min CMake version to 3.14.0, since that's what nanopb 0.4.7
actually needs, despite it declaring a lower minimum version. That's a bug
that I reported and it was fixed after the 0.4.7 release tag.
  • Loading branch information
ivmaykov committed Jul 11, 2023
1 parent b8bb79a commit 210e00e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 2.8)
cmake_minimum_required (VERSION 3.14.0)
project (subzero)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic -Wextra -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wcast-qual -std=gnu11 -DPB_FIELD_16BIT")
Expand Down
2 changes: 1 addition & 1 deletion core/nanopb
Submodule nanopb updated 443 files
13 changes: 6 additions & 7 deletions core/src/checks/rpc_checks.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

// Helper which returns the size of a buffer that would be needed to hold the serialized version of the given
// protobuf structure, assuming that pb_encode_delimited() serialization will be used.
static size_t get_serialized_proto_struct_size(const pb_field_t fields[], const void* const proto_struct) {
static size_t get_serialized_proto_struct_size(const pb_msgdesc_t* const fields, const void* const proto_struct) {
pb_ostream_t stream = PB_OSTREAM_SIZING;
if (!pb_encode_delimited(&stream, fields, proto_struct)) {
ERROR("%s: pb_encode_delimited() failed: %s", __func__, PB_GET_ERROR(&stream));
Expand All @@ -30,7 +30,7 @@ static size_t get_serialized_proto_struct_size(const pb_field_t fields[], const
static bool serialize_proto_struct_to_buffer(
pb_byte_t* const buffer,
const size_t buffer_size,
const pb_field_t fields[],
const pb_msgdesc_t* const fields,
const void* const proto_struct) {
pb_ostream_t ostream = pb_ostream_from_buffer(buffer, buffer_size);
if (!pb_encode_delimited(&ostream, fields, proto_struct)) {
Expand All @@ -46,7 +46,7 @@ static bool serialize_proto_struct_to_buffer(
static bool deserialize_proto_struct_from_buffer(
const pb_byte_t* const buffer,
const size_t buffer_size,
const pb_field_t fields[],
const pb_msgdesc_t* const fields,
void* const proto_struct) {
pb_istream_t istream = pb_istream_from_buffer(buffer, buffer_size);
if (!pb_decode_delimited(&istream, fields, proto_struct)) {
Expand Down Expand Up @@ -88,7 +88,7 @@ int verify_rpc_oversized_message_rejected(void) {
random_buffer(cmd.command.InitWallet.random_bytes.bytes, MASTER_SEED_SIZE);

// Compute the size of the serialized struct.
size_t serialized_size = get_serialized_proto_struct_size(InternalCommandRequest_fields, &cmd);
size_t serialized_size = get_serialized_proto_struct_size(&InternalCommandRequest_msg, &cmd);
if (serialized_size == 0) {
ERROR("%s: error computing serialized request size", __func__);
result = -1;
Expand All @@ -106,7 +106,7 @@ int verify_rpc_oversized_message_rejected(void) {
}

// Serialize the request struct into request_buffer.
if (!serialize_proto_struct_to_buffer(request_buffer, sizeof(request_buffer), InternalCommandRequest_fields, &cmd)) {
if (!serialize_proto_struct_to_buffer(request_buffer, sizeof(request_buffer), &InternalCommandRequest_msg, &cmd)) {
ERROR("%s: serialize_proto_struct_to_buffer() failed", __func__);
result = -1;
goto out;
Expand Down Expand Up @@ -228,8 +228,7 @@ int verify_rpc_oversized_message_rejected(void) {
// note: no need to initialize the response, static bool deserialize_proto_struct_from_buffer() does it via
// pb_decode_delimited().
InternalCommandResponse response;
if (!deserialize_proto_struct_from_buffer(
response_buffer, response_size, InternalCommandResponse_fields, &response)) {
if (!deserialize_proto_struct_from_buffer(response_buffer, response_size, &InternalCommandResponse_msg, &response)) {
ERROR("%s: deserialize_proto_struct_from_buffer() failed", __func__);
result = -1;
goto out;
Expand Down
8 changes: 4 additions & 4 deletions core/src/rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static Result populate_internal_command(InternalCommandRequest * to){
CommandRequest from = CommandRequest_init_default;
// Cannot use pb_decode_delimited as on the coordinator service the java code is generating bytes
// without the delimited values.
if(!pb_decode(&pb_command, CommandRequest_fields, &from)){
if (!pb_decode(&pb_command, &CommandRequest_msg, &from)) {
res = Result_COMMAND_DECODE_FAILED;
ERROR("Could not decode input bytes for command request.");
goto cleanup;
Expand Down Expand Up @@ -96,7 +96,7 @@ static void handle_error(pb_istream_t * input, pb_ostream_t * output, Result err
snprintf(out.response.Error.message, sizeof(out.response.Error.message),
"%s: %s", error_message, PB_GET_ERROR(input));
out.response.Error.has_message = true;
if (!pb_encode_delimited(output, InternalCommandResponse_fields, &out)) {
if (!pb_encode_delimited(output, &InternalCommandResponse_msg, &out)) {
ERROR("Encoding error message about decoding failed: %s",
PB_GET_ERROR(output));
}
Expand All @@ -108,7 +108,7 @@ void handle_incoming_message(pb_istream_t *input, pb_ostream_t *output) {
InternalCommandRequest cmd = InternalCommandRequest_init_default;
InternalCommandResponse out = InternalCommandResponse_init_default;

if (!pb_decode_delimited(input, InternalCommandRequest_fields, &cmd)) {
if (!pb_decode_delimited(input, &InternalCommandRequest_msg, &cmd)) {
handle_error(input, output, Result_COMMAND_DECODE_FAILED, "Decode Input failed");
return;
}
Expand All @@ -126,7 +126,7 @@ void handle_incoming_message(pb_istream_t *input, pb_ostream_t *output) {
}
execute_command(&cmd, &out);

if (!pb_encode_delimited(output, InternalCommandResponse_fields, &out)) {
if (!pb_encode_delimited(output, &InternalCommandResponse_msg, &out)) {
handle_error(input, output, Result_COMMAND_ENCODE_FAILED, "Encoding failed");
return;
}
Expand Down

0 comments on commit 210e00e

Please sign in to comment.