diff --git a/src/apps/snmp/snmp_msg.c b/src/apps/snmp/snmp_msg.c index 7d6eefd1..faa5a5b4 100644 --- a/src/apps/snmp/snmp_msg.c +++ b/src/apps/snmp/snmp_msg.c @@ -1672,7 +1672,7 @@ snmp_complete_outbound_frame(struct snmp_request *request) struct snmp_pbuf_stream inbound_stream; OF_BUILD_EXEC( snmp_pbuf_stream_init(&inbound_stream, request->inbound_pbuf, request->inbound_varbind_offset, request->inbound_varbind_len) ); OF_BUILD_EXEC( snmp_pbuf_stream_init(&(request->outbound_pbuf_stream), request->outbound_pbuf, request->outbound_varbind_offset, request->outbound_pbuf->tot_len - request->outbound_varbind_offset) ); - snmp_pbuf_stream_writeto(&inbound_stream, &(request->outbound_pbuf_stream), 0); + OF_BUILD_EXEC( snmp_pbuf_stream_writeto(&inbound_stream, &(request->outbound_pbuf_stream), 0) ); } frame_size = request->outbound_pbuf_stream.offset; @@ -1683,7 +1683,7 @@ snmp_complete_outbound_frame(struct snmp_request *request) u8_t i; outbound_padding = (8 - (u8_t)((frame_size - request->outbound_scoped_pdu_seq_offset) & 0x07)) & 0x07; for (i = 0; i < outbound_padding; i++) { - snmp_pbuf_stream_write(&request->outbound_pbuf_stream, 0); + OF_BUILD_EXEC( snmp_pbuf_stream_write(&request->outbound_pbuf_stream, 0) ); } } #endif diff --git a/src/apps/snmp/snmpv3_mbedtls.c b/src/apps/snmp/snmpv3_mbedtls.c index b90badf5..ec4ba38b 100644 --- a/src/apps/snmp/snmpv3_mbedtls.c +++ b/src/apps/snmp/snmpv3_mbedtls.c @@ -154,29 +154,36 @@ snmpv3_crypt(struct snmp_pbuf_stream* stream, u16_t length, out_len = LWIP_ARRAYSIZE(out_bytes) ; for (j = 0; j < LWIP_ARRAYSIZE(in_bytes); j++) { - snmp_pbuf_stream_read(&read_stream, &in_bytes[j]); + if (snmp_pbuf_stream_read(&read_stream, &in_bytes[j]) != ERR_OK) { + goto error; + } } - if(mbedtls_cipher_update(&ctx, in_bytes, LWIP_ARRAYSIZE(in_bytes), out_bytes, &out_len) != 0) { + if (mbedtls_cipher_update(&ctx, in_bytes, LWIP_ARRAYSIZE(in_bytes), out_bytes, &out_len) != 0) { goto error; } - snmp_pbuf_stream_writebuf(&write_stream, out_bytes, (u16_t)out_len); + if (snmp_pbuf_stream_writebuf(&write_stream, out_bytes, (u16_t)out_len) != ERR_OK) { + goto error; + } } out_len = LWIP_ARRAYSIZE(out_bytes); - if(mbedtls_cipher_finish(&ctx, out_bytes, &out_len) != 0) { + if (mbedtls_cipher_finish(&ctx, out_bytes, &out_len) != 0) { + goto error; + } + + if (snmp_pbuf_stream_writebuf(&write_stream, out_bytes, (u16_t)out_len) != ERR_OK) { goto error; } - snmp_pbuf_stream_writebuf(&write_stream, out_bytes, (u16_t)out_len); } else if (algo == SNMP_V3_PRIV_ALGO_AES) { u8_t iv_local[16]; cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_AES_128_CFB128); - if(mbedtls_cipher_setup(&ctx, cipher_info) != 0) { + if (mbedtls_cipher_setup(&ctx, cipher_info) != 0) { return ERR_ARG; } - if(mbedtls_cipher_setkey(&ctx, key, 16*8, (mode == SNMP_V3_PRIV_MODE_ENCRYPT)? MBEDTLS_ENCRYPT : MBEDTLS_DECRYPT) != 0) { + if (mbedtls_cipher_setkey(&ctx, key, 16*8, (mode == SNMP_V3_PRIV_MODE_ENCRYPT)? MBEDTLS_ENCRYPT : MBEDTLS_DECRYPT) != 0) { goto error; } @@ -202,11 +209,15 @@ snmpv3_crypt(struct snmp_pbuf_stream* stream, u16_t length, u8_t out_byte; size_t out_len = sizeof(out_byte); - snmp_pbuf_stream_read(&read_stream, &in_byte); - if(mbedtls_cipher_update(&ctx, &in_byte, sizeof(in_byte), &out_byte, &out_len) != 0) { + if (snmp_pbuf_stream_read(&read_stream, &in_byte) != ERR_OK) { + goto error; + } + if (mbedtls_cipher_update(&ctx, &in_byte, sizeof(in_byte), &out_byte, &out_len) != 0) { + goto error; + } + if (snmp_pbuf_stream_write(&write_stream, out_byte) != ERR_OK) { goto error; } - snmp_pbuf_stream_write(&write_stream, out_byte); } } else { return ERR_ARG;