diff options
Diffstat (limited to 'xdr.c')
-rw-r--r-- | xdr.c | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -94,6 +94,9 @@ hal_error_t hal_xdr_encode_fixed_opaque(uint8_t ** const outbuf, const uint8_t * /* arg checks */ hal_assert(outbuf != NULL && *outbuf != NULL && limit != NULL && limit >= *outbuf && (value != NULL || len == 0)); + if (len == 0) + return HAL_OK; + /* buffer overflow check */ /* We need to explicitly check (len > 0xfffffffc) because padding will * round it up to 0. @@ -135,11 +138,22 @@ hal_error_t hal_xdr_decode_fixed_opaque(const uint8_t ** const inbuf, const uint const uint8_t *p; hal_error_t err; + /* arg checks */ + hal_assert(value != NULL || len == 0); + + if (len == 0) + return HAL_OK; + /* get and advance the input data pointer */ - if ((err = hal_xdr_decode_fixed_opaque_ptr(inbuf, limit, &p, len)) == HAL_OK) + if ((err = hal_xdr_decode_fixed_opaque_ptr(inbuf, limit, &p, len)) == HAL_OK) { /* read the data */ memcpy(value, p, len); + /* pad if necessary */ + for (size_t i = len; (i & 3) != 0; ++i) + value[i] = 0; + } + return err; } @@ -204,8 +218,14 @@ hal_error_t hal_xdr_decode_variable_opaque(const uint8_t ** const inbuf, const u /* user buffer overflow check */ if (len_max < xdr_len) return HAL_ERROR_XDR_BUFFER_OVERFLOW; + /* read the data */ memcpy(value, p, xdr_len); + + /* pad if necessary */ + for (size_t i = xdr_len; (i & 3) != 0; ++i) + value[i] = 0; + *len = xdr_len; } |