gpg: Sanitize diagnostic with the original file name.
[gnupg.git] / g10 / compress.c
index c34beec..e7a6f2b 100644 (file)
@@ -15,7 +15,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ * along with this program; if not, see <https://www.gnu.org/licenses/>.
  */
 
 /* Note that the code in compress-bz2.c is nearly identical to the
@@ -38,7 +38,7 @@
 #endif
 
 #include "gpg.h"
-#include "util.h"
+#include "../common/util.h"
 #include "packet.h"
 #include "filter.h"
 #include "main.h"
@@ -182,7 +182,7 @@ do_uncompress( compress_filter_context_t *zfx, z_stream *zs,
            nread = iobuf_read( a, zfx->inbuf + n, count );
            if( nread == -1 ) nread = 0;
            n += nread;
-           /* Algo 1 has no zlib header which requires us to to give
+           /* Algo 1 has no zlib header which requires us to give
             * inflate an extra dummy byte to read. To be on the safe
             * side we allow for up to 4 ff bytes.  */
            if( nread < count && zfx->algo == 1 && zfx->algo1hack < 4) {
@@ -309,15 +309,19 @@ 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;
+        if (push_compress_filter(cd->buf, cfx, cd->algorithm))
+          xfree (cfx);
+    }
     if( callback )
        rc = callback(cd->buf, passthru );
     else
@@ -326,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
@@ -350,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;
 }