From 591f73e04305308d1c00a2607c07e6a4a82dfa1a Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 21 Aug 2013 01:03:24 +0900 Subject: [PATCH] Return error if nghttp2_gzip_inflate is invoked after Z_STREAM_END --- lib/nghttp2_gzip.c | 7 ++++++- lib/nghttp2_gzip.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/nghttp2_gzip.c b/lib/nghttp2_gzip.c index e472ec7f..c22cba94 100644 --- a/lib/nghttp2_gzip.c +++ b/lib/nghttp2_gzip.c @@ -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: diff --git a/lib/nghttp2_gzip.h b/lib/nghttp2_gzip.h index 6f309c89..ca2a5655 100644 --- a/lib/nghttp2_gzip.h +++ b/lib/nghttp2_gzip.h @@ -33,6 +33,7 @@ struct nghttp2_gzip { z_stream zst; + int8_t finished; }; #endif /* NGHTTP2_GZIP_H */