Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nanopb/nanopb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2022-11-24 11:15:59 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2022-11-24 11:15:59 +0300
commit6b878fe29adf0ad954334e8988173815c860a649 (patch)
tree2caf992c4d71fad18b6596ebe5b2c55762095d64
parenteeda15ed4e899cd3d404abf74c1d60e50eb6f790 (diff)
Safeguard substraction in pb_read() (#697)
Previously a custom stream callback could modify bytes_left, causing the substraction to wrap.
-rw-r--r--pb_decode.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/pb_decode.c b/pb_decode.c
index 5405c87..58ee5f7 100644
--- a/pb_decode.c
+++ b/pb_decode.c
@@ -111,7 +111,11 @@ bool checkreturn pb_read(pb_istream_t *stream, pb_byte_t *buf, size_t count)
return false;
#endif
- stream->bytes_left -= count;
+ if (stream->bytes_left < count)
+ stream->bytes_left = 0;
+ else
+ stream->bytes_left -= count;
+
return true;
}