From f7f4cdb45812fbaa518dac2984ad5271b82d997f Mon Sep 17 00:00:00 2001 From: Wiktor Garbacz Date: Wed, 28 Feb 2024 05:46:27 -0800 Subject: [PATCH] More complete error handling in `SerializeProto` PiperOrigin-RevId: 611073556 Change-Id: Id29c3dbe15bb55c7d4e68d9a3e1c82327af0ad23 --- sandboxed_api/proto_helper.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sandboxed_api/proto_helper.cc b/sandboxed_api/proto_helper.cc index 868033d..0c3623b 100644 --- a/sandboxed_api/proto_helper.cc +++ b/sandboxed_api/proto_helper.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "absl/status/status.h" @@ -47,7 +48,11 @@ absl::StatusOr> SerializeProto( // Wrap protobuf in a envelope so that we know the name of the protobuf // structure when deserializing in the sandboxee. ProtoArg proto_arg; - proto_arg.set_protobuf_data(proto.SerializeAsString()); + std::string proto_data; + if (!proto.SerializeToString(&proto_data)) { + return absl::InternalError("Unable to serialize proto data"); + } + proto_arg.set_protobuf_data(std::move(proto_data)); proto_arg.set_full_name(proto.GetTypeName()); std::vector serialized_proto(proto_arg.ByteSizeLong()); if (!proto_arg.SerializeToArray(serialized_proto.data(),