Skip to content

Commit

Permalink
ensure that decoded z_bytes never contanin non-_is_alloc slice
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Jun 27, 2024
1 parent 57e2022 commit baf0d00
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/zenoh-pico/collections/bytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int8_t _z_bytes_from_uint64(_z_bytes_t *b, uint64_t val);
int8_t _z_bytes_from_float(_z_bytes_t *b, float val);
int8_t _z_bytes_from_double(_z_bytes_t *b, double val);
size_t _z_bytes_to_buf(const _z_bytes_t *bytes, uint8_t *dst, size_t len);
int8_t _z_bytes_from_buf(_z_bytes_t *b, uint8_t *src, size_t len);
int8_t _z_bytes_from_buf(_z_bytes_t *b, const uint8_t *src, size_t len);
int8_t _z_bytes_serialize_from_pair(_z_bytes_t *out, _z_bytes_t *first, _z_bytes_t *second);
int8_t _z_bytes_deserialize_into_pair(const _z_bytes_t *bs, _z_bytes_t *first_out, _z_bytes_t *second_out);
_z_slice_t _z_bytes_try_get_contiguous(const _z_bytes_t *bs);
Expand Down
2 changes: 1 addition & 1 deletion src/collections/bytes.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int8_t _z_bytes_from_slice(_z_bytes_t *b, _z_slice_t s) {
return _z_arc_slice_svec_append(&b->_slices, &arc_s) ? _Z_RES_OK : _Z_ERR_SYSTEM_OUT_OF_MEMORY;
}

int8_t _z_bytes_from_buf(_z_bytes_t *b, uint8_t *src, size_t len) {
int8_t _z_bytes_from_buf(_z_bytes_t *b, const uint8_t *src, size_t len) {
*b = _z_bytes_null();
_z_slice_t s = _z_slice_wrap_copy(src, len);
if (s.len != len) return _Z_ERR_SYSTEM_OUT_OF_MEMORY;
Expand Down
6 changes: 5 additions & 1 deletion src/protocol/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,11 @@ int8_t _z_slice_decode(_z_slice_t *bs, _z_zbuf_t *zbf) { return _z_slice_decode_
int8_t _z_bytes_decode(_z_bytes_t *bs, _z_zbuf_t *zbf) {
_z_slice_t s;
_Z_RETURN_IF_ERR(_z_slice_decode(&s, zbf));
return _z_bytes_from_slice(bs, s);
if (s._is_alloc) {
return _z_bytes_from_slice(bs, s);
} else {
return _z_bytes_from_buf(bs, s.start, s.len);
}
}

int8_t _z_bytes_encode_val(_z_wbuf_t *wbf, const _z_bytes_t *bs) {
Expand Down

0 comments on commit baf0d00

Please sign in to comment.