Return error if nghttp2_gzip_inflate is invoked after Z_STREAM_END

This commit is contained in:
Tatsuhiro Tsujikawa 2013-08-21 01:03:24 +09:00
parent 4d51def65f
commit 591f73e043
2 changed files with 7 additions and 1 deletions

View File

@ -33,6 +33,7 @@ int nghttp2_gzip_inflate_new(nghttp2_gzip **inflater_ptr)
if(*inflater_ptr == NULL) {
return NGHTTP2_ERR_NOMEM;
}
(*inflater_ptr)->finished = 0;
(*inflater_ptr)->zst.next_in = Z_NULL;
(*inflater_ptr)->zst.avail_in = 0;
(*inflater_ptr)->zst.zalloc = Z_NULL;
@ -59,6 +60,9 @@ int nghttp2_gzip_inflate(nghttp2_gzip *inflater,
const uint8_t *in, size_t *inlen_ptr)
{
int rv;
if(inflater->finished) {
return NGHTTP2_ERR_GZIP;
}
inflater->zst.avail_in = *inlen_ptr;
inflater->zst.next_in = (unsigned char*)in;
inflater->zst.avail_out = *outlen_ptr;
@ -69,8 +73,9 @@ int nghttp2_gzip_inflate(nghttp2_gzip *inflater,
*inlen_ptr -= inflater->zst.avail_in;
*outlen_ptr -= inflater->zst.avail_out;
switch(rv) {
case Z_OK:
case Z_STREAM_END:
inflater->finished = 1;
case Z_OK:
case Z_BUF_ERROR:
return 0;
case Z_DATA_ERROR:

View File

@ -33,6 +33,7 @@
struct nghttp2_gzip {
z_stream zst;
int8_t finished;
};
#endif /* NGHTTP2_GZIP_H */