diff options
author | Alice Wang <aw@squareup.com> | 2017-05-01 10:23:54 +0300 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2017-05-03 07:42:02 +0300 |
commit | bfeb7655dd383a7f3ec37bd97f7ec6458f5efdaf (patch) | |
tree | 7eded9d1444bae05f985736fd0fbc733f96ba02e /pb_encode.c | |
parent | 1d527d0726346cfd1c6ffb0b36bebd73a366a8c1 (diff) |
The max size for encoding strings must leave spaces for a null terminator in the case where the field type isn't a pointer.
Diffstat (limited to 'pb_encode.c')
-rw-r--r-- | pb_encode.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/pb_encode.c b/pb_encode.c index 05d691d..0661da0 100644 --- a/pb_encode.c +++ b/pb_encode.c @@ -769,7 +769,18 @@ static bool checkreturn pb_enc_string(pb_ostream_t *stream, const pb_field_t *fi const char *p = (const char*)src; if (PB_ATYPE(field->type) == PB_ATYPE_POINTER) + { max_size = (size_t)-1; + } + else + { + /* pb_dec_string() assumes string fields end with a null + * terminator when the type isn't PB_ATYPE_POINTER, so we + * shouldn't allow more than max-1 bytes to be written to + * allow space for the null terminator. + */ + max_size -= 1; + } if (src == NULL) { |