diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2019-10-02 10:56:49 +0300 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2019-10-02 11:16:51 +0300 |
commit | eab98ebbd68489987b8399d37cf5517792353fc7 (patch) | |
tree | 57c2d8f7d9749de5ea8031ad1872953daba4957e /pb_decode.h | |
parent | 186ee03dd3d2e66204646863eee61d7e5d01c272 (diff) |
Fix undefined behavior with bool fields (#434)
Previously nanopb didn't enforce that decoded bool fields
had valid true/false values. This could lead to undefined
behavior in user code.
This has potential security implications when
1) message contains bool field (has_ fields are safe)
and
2) user code uses ternary operator dependent on the field value,
such as: int value = msg.my_bool ? 1234 : 0
and
3) the value returned from ternary operator affects a memory access,
such as: data_array[value] = 9999
Diffstat (limited to 'pb_decode.h')
-rw-r--r-- | pb_decode.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/pb_decode.h b/pb_decode.h index e55e3c3..e42a273 100644 --- a/pb_decode.h +++ b/pb_decode.h @@ -144,7 +144,7 @@ bool pb_decode_tag(pb_istream_t *stream, pb_wire_type_t *wire_type, uint32_t *ta /* Skip the field payload data, given the wire type. */ bool pb_skip_field(pb_istream_t *stream, pb_wire_type_t wire_type); -/* Decode an integer in the varint format. This works for bool, enum, int32, +/* Decode an integer in the varint format. This works for enum, int32, * int64, uint32 and uint64 field types. */ #ifndef PB_WITHOUT_64BIT bool pb_decode_varint(pb_istream_t *stream, uint64_t *dest); @@ -152,10 +152,13 @@ bool pb_decode_varint(pb_istream_t *stream, uint64_t *dest); #define pb_decode_varint pb_decode_varint32 #endif -/* Decode an integer in the varint format. This works for bool, enum, int32, +/* Decode an integer in the varint format. This works for enum, int32, * and uint32 field types. */ bool pb_decode_varint32(pb_istream_t *stream, uint32_t *dest); +/* Decode a bool value in varint format. */ +bool pb_decode_bool(pb_istream_t *stream, bool *dest); + /* Decode an integer in the zig-zagged svarint format. This works for sint32 * and sint64. */ #ifndef PB_WITHOUT_64BIT |