From c1bd1a6ad3479088fef09c02e39b70bea0a718ae Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Thu, 7 Feb 2013 17:56:52 +0200 Subject: [PATCH] Fix error message bugs with packed arrays. Error messages were not propagated correctly with PB_HTYPE_ARRAY. Error status (boolean return value) was correct. Update issue 56 Status: FixedInGit --- pb_decode.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pb_decode.c b/pb_decode.c index b25f3f5..d474113 100644 --- a/pb_decode.c +++ b/pb_decode.c @@ -361,7 +361,7 @@ static bool checkreturn decode_field(pb_istream_t *stream, pb_wire_type_t wire_t && PB_LTYPE(iter->current->type) <= PB_LTYPE_LAST_PACKABLE) { /* Packed array */ - bool status; + bool status = true; size_t *size = (size_t*)iter->pSize; pb_istream_t substream; if (!pb_make_string_substream(stream, &substream)) @@ -371,11 +371,17 @@ static bool checkreturn decode_field(pb_istream_t *stream, pb_wire_type_t wire_t { void *pItem = (uint8_t*)iter->pData + iter->current->data_size * (*size); if (!func(&substream, iter->current, pItem)) - return false; + { + status = false; + break; + } (*size)++; } - status = (substream.bytes_left == 0); pb_close_string_substream(stream, &substream); + + if (substream.bytes_left != 0) + PB_RETURN_ERROR(stream, "array overflow"); + return status; } else -- 2.16.6