From c31abf84659dbda5503dd9f3aa3449520bcd1b84 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 13 Apr 2018 10:09:02 +0900 Subject: g10: Push compress filter only if compressed. * g10/compress.c (handle_compressed): Fix memory leak. -- All other calls of push_compress_filter checks ALGO, so, do it here, too. GnuPG-bug-id: 3898 Signed-off-by: NIIBE Yutaka --- g10/compress.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'g10/compress.c') diff --git a/g10/compress.c b/g10/compress.c index 61bb756f2..67c9c9bd6 100644 --- a/g10/compress.c +++ b/g10/compress.c @@ -309,15 +309,18 @@ int handle_compressed (ctrl_t ctrl, void *procctx, PKT_compressed *cd, int (*callback)(IOBUF, void *), void *passthru ) { - compress_filter_context_t *cfx; int rc; if(check_compress_algo(cd->algorithm)) return GPG_ERR_COMPR_ALGO; - cfx = xmalloc_clear (sizeof *cfx); - cfx->release = release_context; - cfx->algo = cd->algorithm; - push_compress_filter(cd->buf,cfx,cd->algorithm); + if(cd->algorithm) { + compress_filter_context_t *cfx; + + cfx = xmalloc_clear (sizeof *cfx); + cfx->release = release_context; + cfx->algo = cd->algorithm; + push_compress_filter(cd->buf,cfx,cd->algorithm); + } if( callback ) rc = callback(cd->buf, passthru ); else -- cgit v1.2.3 From d26363e4f1933781c86cbe87077fbf1b9a2b64d8 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 2 May 2018 19:44:10 +0200 Subject: gpg: Fix minor memory leak in the compress filter. * g10/compress.c (push_compress_filter2): Return an error if no filter was pushed. (push_compress_filter): Ditto. (handle_compressed): Free CFX if no filter was pushed. * g10/import.c (read_block): Ditto. -- GnuPG-bug-id: 3898, 3930 Signed-off-by: Werner Koch --- g10/compress.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'g10/compress.c') diff --git a/g10/compress.c b/g10/compress.c index 67c9c9bd6..e7a6f2b11 100644 --- a/g10/compress.c +++ b/g10/compress.c @@ -319,7 +319,8 @@ handle_compressed (ctrl_t ctrl, void *procctx, PKT_compressed *cd, cfx = xmalloc_clear (sizeof *cfx); cfx->release = release_context; cfx->algo = cd->algorithm; - push_compress_filter(cd->buf,cfx,cd->algorithm); + if (push_compress_filter(cd->buf, cfx, cd->algorithm)) + xfree (cfx); } if( callback ) rc = callback(cd->buf, passthru ); @@ -329,16 +330,20 @@ handle_compressed (ctrl_t ctrl, void *procctx, PKT_compressed *cd, return rc; } -void +gpg_error_t push_compress_filter(IOBUF out,compress_filter_context_t *zfx,int algo) { - push_compress_filter2(out,zfx,algo,0); + return push_compress_filter2(out,zfx,algo,0); } -void + +/* Push a compress filter and return 0 if that succeeded. */ +gpg_error_t push_compress_filter2(IOBUF out,compress_filter_context_t *zfx, int algo,int rel) { + gpg_error_t err = gpg_error (GPG_ERR_FALSE); + if(algo>=0) zfx->algo=algo; else @@ -353,16 +358,20 @@ push_compress_filter2(IOBUF out,compress_filter_context_t *zfx, case COMPRESS_ALGO_ZIP: case COMPRESS_ALGO_ZLIB: iobuf_push_filter2(out,compress_filter,zfx,rel); + err = 0; break; #endif #ifdef HAVE_BZIP2 case COMPRESS_ALGO_BZIP2: iobuf_push_filter2(out,compress_filter_bz2,zfx,rel); + err = 0; break; #endif default: BUG(); } + + return err; } -- cgit v1.2.3