aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Shelton <stuart@shelton.me>2018-02-14 20:34:43 +0000
committerStuart Shelton <stuart@shelton.me>2018-02-14 20:34:43 +0000
commit310a06528b2581c3b5e79b9460b783e4d2b5ed3a (patch)
tree15e09a3f2c021de7e6cf834de791ecc543bc4ed0 /app-antivirus
parentUpdate file mdraid.rc, affecting sys-fs/mdadm (diff)
downloadsrcshelton-310a06528b2581c3b5e79b9460b783e4d2b5ed3a.tar.gz
srcshelton-310a06528b2581c3b5e79b9460b783e4d2b5ed3a.tar.bz2
srcshelton-310a06528b2581c3b5e79b9460b783e4d2b5ed3a.zip
Add app-antivirus/clamav-0.99.3-r1
Diffstat (limited to 'app-antivirus')
-rw-r--r--app-antivirus/clamav/Manifest3
-rw-r--r--app-antivirus/clamav/clamav-0.99.3-r1.ebuild163
-rw-r--r--app-antivirus/clamav/files/clamav-0.99.3-fix-fd-leaks-in-cli_scanscript.patch132
3 files changed, 298 insertions, 0 deletions
diff --git a/app-antivirus/clamav/Manifest b/app-antivirus/clamav/Manifest
index 3dd5aad5..637f942b 100644
--- a/app-antivirus/clamav/Manifest
+++ b/app-antivirus/clamav/Manifest
@@ -4,6 +4,7 @@ AUX clamav-0.99-zlib.patch 805 SHA256 eff89272cfd0cb224f850b3ee2fbe50cb852b01203
AUX clamav-0.99.2-bytecode_api.patch 1531 SHA256 b0619bca555a8069289bb7299e0708cfdc86b566197b2c2e780619bfdf26aa0d SHA512 05d5d9ce0aa64a178a1dfce0e37e2648f42a31a78b89c6d54203899a8334d0ef5a0f1484803932e9a09745bed3f11865c9ccedf175e7e09fcb4f3d621aa6f029 WHIRLPOOL 151d2a5545d923ec4bbe29347db4f9c2d6f84fdd1a89467d2d21b14b2a1e78ebb405c2b3e871406408c0b1463ea0d395393d66e3a33a0472ea0f56e5e35b5a58
AUX clamav-0.99.2-gcc-6.patch 4476 SHA256 b2960553243392a4298f37d5ef537296e989e95f7cc084800b8e3ab6a251be6d SHA512 b30ed8b888af3697294c1a2aa96a335b3b1035f4f76e3bcf6c243dca7bdc5921a9bb182fbfd5e0e7f1bb9dce93b2312927e28f78edae466d31200a2be50f3a85 WHIRLPOOL a3a03f600edc287984aedcdf23369071691022a78f192d0ee5d9eec14243fcac26f9b7189fbd3baa8d4ab2906e8db37a427d60c8dae4fc5b835f44a308f22cc3
AUX clamav-0.99.2-tinfo.patch 656 SHA256 6e68af3dcc41a693ca5f8a191a59a732e014c42ea58e902d62799f3cbc20c7e3 SHA512 33e375e8f4e74f284e9d14adaa8ef095bdb67b2f62e4b7c5e9c38a3c5f955106173e402859fabf44ada40ae08cceb3fca79322f8854f47d850816064641f4451 WHIRLPOOL d0ea141ca3495316dd462c30ee6311e9dc5d752c60e50b1f825c5b7a367d8ab8a7cb9d16574c35b7de901096811098ddbf77189595c7dda7c75b267f6a7aaeae
+AUX clamav-0.99.3-fix-fd-leaks-in-cli_scanscript.patch 3554 SHA256 6e787a302e788feea4cc072d97c4eac3394ea49e5495d55e0ab59b7e629ec82d SHA512 e0dfecff8adb1e30f4c7a20271fd8731ebbb20449a532d70977f7491d8539fc8ed74f851f6903f6265a2e660f9471341e68cc0651e5f94356179ff1f328ada0c WHIRLPOOL 1ac0009f9766e9a7972fe9741b065f651acc1789c75aeb102d71929ce96c0d9386ca3956364f5fb8517d5a54e53375a07600729e503acdfd8bf3216ffa04bfe6
AUX clamav-milter.README.gentoo 1124 SHA256 5e7b142b68964bc3463b077e5698fa77cace45ea9612258b1e1849cee944dd11 SHA512 1c6160e48eddd28f83ec5f24757f788781cef55789d1934dfccc12c7c5e5635a226d26b0983cab7344c142f5a2f1db172640b1d0e6c840a6fa83abed9be1211a WHIRLPOOL f85b17448fd93205e2f38d024b96410cc8d143d077201e0a1b8f4cda95ae2447a70eded4cb90968a593ad2637229300fa04bfe5dba96d3d68c2d09c105ee3f16
AUX clamav-milter.service 284 SHA256 b371725acfd102b6b7ee15ab0059e8795b7d3716d041d0dc11d0fe8f7454d5a9 SHA512 442148ac3c42ecbb893de5c6edde337b72a745d20f6c5ffa33131f9a0b2daadcffac39b686ada986a5ab500ea7b9153c448abc1b819e15fef488da1812bb0cee WHIRLPOOL 56b4ed79e06c764df37022f0638ceddb5fe8185c54b2e460b076a46ed4f5a68b67fb7966d424dabe836bfd7d6b9d770eb60cad4633ee17083baa50ad2c0a89cd
AUX clamav-milter.service-r1 307 SHA256 6fde803fe67a73f7f17681a9c7db7bdaa6cdcc227a15ec03c8067e43899eec9d SHA512 19e49cfef98d8f3c213bb291cd9c622c1bd1b7c255feef8ccdffddea38893631f2446a4f4f3718cbb87a07bac339805fc78ddacce0b2a55a180f2d23e5b8ad48 WHIRLPOOL ffc84b00f5bafd9487801262dc40368632ed0d023837b691d16ba65d0011957c8bb1ce9671a209f194e5411f7b379de215ddbf7110636f719bafe3921501b0b6
@@ -24,6 +25,7 @@ DIST clamav-0.98.5.tar.gz 15146379 SHA256 9c2f37d5fa9033936468237f6f4b29289f3079
DIST clamav-0.98.7.tar.gz 15118851 SHA256 282417b707740de13cd8f18d4cbca9ddd181cf96b444db2cad98913a5153e272 SHA512 acf01961472c13ccb219420cc3fa3c3e6f8a733edef371dbc04ce5867900aa1535e956ec8ad50d31c8f872a0a1d79fcccac944cd86e29ecdfa4af18f7fd5afb9 WHIRLPOOL c9f2e6f52f07f68bdcccf55ca1aab0bf3deaa6963279459d64ecca076a9ed0ef53c25996b2b673e9746833822df24689a9fab0654064c5ee6ed372a86966fbb6
DIST clamav-0.98.tar.gz 37075245 SHA256 113450537f46ed47f010a179be333a0dcd79eac13f264dce26db7aac8d52b3b6 SHA512 532f9fa2616065879b3ecace2672fad26cf3863943e0ecb8835fbed7e5907600ef50b8df820a08a6586bf77c9bf7c6e50af671f31b7c3ee372c31745a173099f WHIRLPOOL a4ee9efd09193aee7fd740dbb60acabdd4a1f6d5171a4e0fa220441457e3431bf99b27c7300ca0e3e124bb5406f65acf106fa51bfc34d87335ca83ccbc942979
DIST clamav-0.99.2.tar.gz 16067497 SHA256 167bd6a13e05ece326b968fdb539b05c2ffcfef6018a274a10aeda85c2c0027a SHA512 7744ba8a344b163cf98e9737cddfd25d2120b34ee9c4518380e028c9ec3cd50127b198b0dfa9fde30f5ce9aab0c0e6384712fbc11287e77d16ce052fd7b6ac44 WHIRLPOOL 371dc56c3ffa0ff40381d451687a9331a0587943a048604c6667e1018fbfe5559b023654d29f47505bd69a1a44f88adfb5b93b7c55c8cbc6f0bbfcbf836bf631
+DIST clamav-0.99.3.tar.gz 16082645 SHA256 00fa5292a6e00a3a4035b826267748965d5d2c4943d8ff417d740238263e8e84 SHA512 0d3c75d571ed4aa4937ef2b743a39a9a144f5adfd6f56f71046e5a8387b8ed7c3c4d9a4196aa85750f9ec4dc545720fdd659289d0cce086ab13a7cc505a0ab3e WHIRLPOOL 543392a94a7a8f2ef0f8657531aa349fdd1192cbeb1f7eac19a333c35bbe95fef758aabf7584177a5bba6e58cf5416cd11cc1d3c8da0f90ac7b93de56beccc34
DIST clamav-0.99.tar.gz 15968038 SHA256 d2792c8cfadd685fffc40b2199679628815df031fd3149ccf961649fc8787ea9 SHA512 328e66fa412ba61f5e44c839b254c7a84d2ce7821fda6cf29e4ee9532c06e45bdec62f202ca561223e984fff170bfd8280e5cc8e306c09a3017b17e7db3bbf56 WHIRLPOOL 696b425c0d3a6639d627e6dba000a57c4e532232f9f42a564a992c0b459d8041a1947b09548d99b621a5685c78d91045adf4b61731242f55eda2b8d5150fc8b8
EBUILD clamav-0.97.8-r2.ebuild 4135 SHA256 689911934856c0a2ab985e4247f81553531b6e89479e2996dc5b0f8f351a90df SHA512 4962ff4198a9754efabee3b9b36930d9393841f02ac73b4a1c2b353defc2a81dc1517124dc19d1e0fcbae64a1f3d9271679092994223470361a60cba242c8ce4 WHIRLPOOL 3885f434178562ce39053b723dddc6662049f3cd92129dcfb61965ce5e9558190b67c18e4fcbcdd145842bab8989d273b2f3be37ae08d48748073615ee667a39
EBUILD clamav-0.97.8.ebuild 3809 SHA256 6759b6fc1154459067b3aa9dd86e9a623e1372146081c5867f615c7567e6744f SHA512 8e0ef02f76d360a330bd1c0380a0aa4b645ef3a0b7844ccf9940ac599f8a09ca02247f55d1c2908cb12ae8cdcbc4a07e87b6dbc3e1614736b087f00bd6246298 WHIRLPOOL 2b3cfab0847916e5834ca0d575b363d0b5856eb708bfaf427a2927e4a1c1b64b02212fbec35dbfaf6b9e604f9bd25fc7d4373892f5dd73c7befdc446a5f13eea
@@ -33,4 +35,5 @@ EBUILD clamav-0.98.5.ebuild 4786 SHA256 39080bf04b4df567a6309e9f7fb2eb5fa0be2eae
EBUILD clamav-0.98.7.ebuild 4757 SHA256 3ef489a7708ad36ee306b949069611308c52d108bfc31c9769e00c772231df80 SHA512 28de254360e1015cc874966c6bb3061c60901da494805c69483e9c1e22965b370ac1227323193d4ebd3492c67f4cf50f7bc8bac0402d1a62be96ae4196ca1562 WHIRLPOOL f082fca5d6f15f2d6246c46e3abf3592cf762e176e2421826433cdde66b44e5d791254db629ba93b23397d588f246195db3099b1b988020e2b645e3d02aa43e7
EBUILD clamav-0.98.ebuild 4501 SHA256 a9184da412054899bed4f9b7e9fe544b93fd71c04b7febc1d16f8c365f550612 SHA512 c1512232af2331867731d3eb2b8d7ff046c28ea4f6f02722ab9e93a078b12cb21ed6071ff93112edf05fe4671a7697722b4797a4650aa33628609066a3754bc2 WHIRLPOOL 918dc18a16748482aad71778d23ad04603f45f3e186ea479680b7f158fdd36de37ce7e96a6c1aa7e3e6201dc60e6cfd628ad59ba4477dc32d51948cb83058a8b
EBUILD clamav-0.99.2-r1.ebuild 5290 SHA256 ad3842a63e6a009365a434865c3ad0af0b5a9669c9a44ac4f0b795ca22a1a366 SHA512 e76679323798b9a6d57f233452dd811c8f96e5ae5d736d4422dae39a7c59bf4e71e577c58b08f8dd843c2e8d3e33613a10d74fd99c25c163099c5b4f362f3675 WHIRLPOOL c3e4971d70ff24e618ef170d9233ecee8e92d4ab426fa39bee5b0b5de54c935adcd5c6477182d81c20224d25f2a10388277d76d80e96375e589802d44c85979e
+EBUILD clamav-0.99.3-r1.ebuild 5327 SHA256 8ebeaba28890d919e2d3821a6210f0abc3bff796c81a7e6d215108d004e15286 SHA512 74da9e570c4f04e40dbe250c370d81970e88ca7fcf6fc4cbf641e99a77747d7f4af4bc424716704f9aca7759767dab01fa3b597ad28f7e1b7f2f2e7241edc7aa WHIRLPOOL f4ca7843695c209611182784a339581531efeb17e261ed00a93688a487e800c6a9a20e23e30c7414937c4c41b84e0ce01202e88dc6d8705b1ffc380f8784aa56
EBUILD clamav-0.99.ebuild 5052 SHA256 30ef948c4a96dca9617c559aec5a8bac6b7da315f33c214e127a5e7565019790 SHA512 a1cfbded934b1588e650a9b8d7ebce11fde774a4f349f825467cbf331a02a81763633295df8b9d4d8863bdaa95c1f32af8a924f6e740b27e0acbebd93e072a91 WHIRLPOOL b294cb76dd0c6f0ea656d0b27f4e83c088a368b7a6e8ab3c8be8841420d42a8f30e450aab53b9da43a2082c06de97a368eb4fc9dc125a8893a108b4d732e456b
diff --git a/app-antivirus/clamav/clamav-0.99.3-r1.ebuild b/app-antivirus/clamav/clamav-0.99.3-r1.ebuild
new file mode 100644
index 00000000..fc7ca858
--- /dev/null
+++ b/app-antivirus/clamav/clamav-0.99.3-r1.ebuild
@@ -0,0 +1,163 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+
+inherit autotools eutils flag-o-matic user systemd
+
+DESCRIPTION="Clam Anti-Virus Scanner"
+HOMEPAGE="http://www.clamav.net/"
+SRC_URI="https://www.clamav.net/downloads/production/${P}.tar.gz"
+
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="~alpha amd64 ~arm ~hppa ia64 ppc ~ppc64 ~sparc x86 ~x86-fbsd ~amd64-linux ~x86-linux ~ppc-macos ~sparc-solaris ~x86-solaris"
+IUSE="bzip2 clamdtop iconv ipv6 libressl milter metadata-analysis-api selinux static-libs systemd uclibc"
+
+CDEPEND="bzip2? ( app-arch/bzip2 )
+ clamdtop? ( sys-libs/ncurses:0 )
+ iconv? ( virtual/libiconv )
+ metadata-analysis-api? ( dev-libs/json-c:= )
+ milter? ( || ( mail-filter/libmilter mail-mta/sendmail ) )
+ dev-libs/libtommath
+ >=sys-libs/zlib-1.2.2:=
+ !libressl? ( dev-libs/openssl:0= )
+ libressl? ( dev-libs/libressl:0= )
+ sys-devel/libtool
+ || ( dev-libs/libpcre2 >dev-libs/libpcre-6 )
+ !!<app-antivirus/clamav-0.99"
+# hard block clamav < 0.99 due to linking problems Bug #567680
+# openssl is now *required* see this link as to why
+# http://blog.clamav.net/2014/02/introducing-openssl-as-dependency-to.html
+DEPEND="${CDEPEND}
+ virtual/pkgconfig"
+RDEPEND="${CDEPEND}
+ selinux? ( sec-policy/selinux-clamav )"
+
+DOCS=( AUTHORS BUGS ChangeLog FAQ INSTALL NEWS README UPGRADE )
+PATCHES=(
+ "${FILESDIR}"/${PN}-0.99.2-gcc-6.patch
+ "${FILESDIR}"/${PN}-0.99.2-tinfo.patch
+ "${FILESDIR}"/${PN}-0.99.2-bytecode_api.patch
+ "${FILESDIR}"/${PN}-0.99.2-pcre2-compile-erroffset.patch
+ "${FILESDIR}"/${PN}-0.99.3-fix-fd-leaks-in-cli_scanscript.patch
+)
+
+pkg_setup() {
+ enewgroup clamav
+ enewuser clamav -1 -1 /dev/null clamav
+}
+
+src_prepare() {
+ default
+
+ eautoconf
+}
+
+src_configure() {
+ use ppc64 && append-flags -mminimal-toc
+ use uclibc && export ac_cv_type_error_t=yes
+
+ econf \
+ $(use_enable bzip2) \
+ $(use_enable clamdtop) \
+ $(use_enable ipv6) \
+ $(use_enable milter) \
+ $(use_enable static-libs static) \
+ $(use_with iconv) \
+ $(use_with metadata-analysis-api libjson /usr) \
+ --cache-file="${S}"/config.cache \
+ --disable-experimental \
+ --disable-gcc-vcheck \
+ --disable-zlib-vcheck \
+ --enable-id-check \
+ --with-dbdir="${EPREFIX}"/var/lib/clamav \
+ --with-system-tommath \
+ --with-zlib="${EPREFIX}"/usr
+}
+
+src_install() {
+ default
+
+ rm -rf "${ED}"/var/lib/clamav
+ newinitd "${FILESDIR}"/clamd.initd-r6 clamd
+ newconfd "${FILESDIR}"/clamd.conf-r1 clamd
+
+ if use systemd; then
+ systemd_dotmpfilesd "${FILESDIR}/tmpfiles.d/clamav.conf"
+ systemd_newunit "${FILESDIR}/clamd_at.service" "clamd@.service"
+ systemd_dounit "${FILESDIR}/clamd.service"
+ systemd_dounit "${FILESDIR}/freshclamd.service"
+ fi
+
+ keepdir /var/lib/clamav
+ fowners clamav:clamav /var/lib/clamav
+ keepdir /var/log/clamav
+ fowners clamav:clamav /var/log/clamav
+
+ dodir /etc/logrotate.d
+ insinto /etc/logrotate.d
+ newins "${FILESDIR}"/clamav.logrotate clamav
+
+ # Modify /etc/{clamd,freshclam}.conf to be usable out of the box
+ sed -i -e "s:^\(Example\):\# \1:" \
+ -e "s:.*\(PidFile\) .*:\1 ${EPREFIX}/var/run/clamav/clamd.pid:" \
+ -e "s:.*\(LocalSocket\) .*:\1 ${EPREFIX}/var/run/clamav/clamd.sock:" \
+ -e "s:.*\(User\) .*:\1 clamav:" \
+ -e "s:^\#\(LogFile\) .*:\1 ${EPREFIX}/var/log/clamav/clamd.log:" \
+ -e "s:^\#\(LogTime\).*:\1 yes:" \
+ -e "s:^\#\(AllowSupplementaryGroups\).*:\1 yes:" \
+ "${ED}"/etc/clamd.conf.sample || die
+ sed -i -e "s:^\(Example\):\# \1:" \
+ -e "s:.*\(PidFile\) .*:\1 ${EPREFIX}/var/run/clamav/freshclam.pid:" \
+ -e "s:.*\(DatabaseOwner\) .*:\1 clamav:" \
+ -e "s:^\#\(UpdateLogFile\) .*:\1 ${EPREFIX}/var/log/clamav/freshclam.log:" \
+ -e "s:^\#\(NotifyClamd\).*:\1 ${EPREFIX}/etc/clamd.conf:" \
+ -e "s:^\#\(ScriptedUpdates\).*:\1 yes:" \
+ -e "s:^\#\(AllowSupplementaryGroups\).*:\1 yes:" \
+ "${ED}"/etc/freshclam.conf.sample || die
+
+ if use milter ; then
+ # MilterSocket one to include ' /' because there is a 2nd line for
+ # inet: which we want to leave
+ dodoc "${FILESDIR}"/clamav-milter.README.gentoo
+ sed -i -e "s:^\(Example\):\# \1:" \
+ -e "s:.*\(PidFile\) .*:\1 ${EPREFIX}/var/run/clamav/clamav-milter.pid:" \
+ -e "s+^\#\(ClamdSocket\) .*+\1 unix:${EPREFIX}/var/run/clamav/clamd.sock+" \
+ -e "s:.*\(User\) .*:\1 clamav:" \
+ -e "s+^\#\(MilterSocket\) /.*+\1 unix:${EPREFIX}/var/run/clamav/clamav-milter.sock+" \
+ -e "s:^\#\(AllowSupplementaryGroups\).*:\1 yes:" \
+ -e "s:^\#\(LogFile\) .*:\1 ${EPREFIX}/var/log/clamav/clamav-milter.log:" \
+ "${ED}"/etc/clamav-milter.conf.sample || die
+ cat >> "${ED}"/etc/conf.d/clamd <<-EOF
+ MILTER_NICELEVEL=19
+ START_MILTER=no
+ EOF
+
+ use systemd && systemd_newunit "${FILESDIR}/clamav-milter.service-r1" clamav-milter.service
+ fi
+
+ for i in clamd freshclam clamav-milter
+ do
+ [[ -f "${D}"/etc/"${i}".conf.sample ]] && mv "${D}"/etc/"${i}".conf{.sample,}
+ done
+
+ prune_libtool_files --all
+}
+
+src_test() {
+ emake quick-check
+}
+
+pkg_postinst() {
+ if use milter ; then
+ elog "For simple instructions how to setup the clamav-milter read the"
+ elog "clamav-milter.README.gentoo in /usr/share/doc/${PF}"
+ fi
+ if test -z $(find "${ROOT}"var/lib/clamav -maxdepth 1 -name 'main.c*' -print -quit) ; then
+ ewarn "You must run freshclam manually to populate the virus database files"
+ ewarn "before starting clamav for the first time.\n"
+ fi
+}
+
+# vi: set diffopt=iwhite,filler:
diff --git a/app-antivirus/clamav/files/clamav-0.99.3-fix-fd-leaks-in-cli_scanscript.patch b/app-antivirus/clamav/files/clamav-0.99.3-fix-fd-leaks-in-cli_scanscript.patch
new file mode 100644
index 00000000..a457a717
--- /dev/null
+++ b/app-antivirus/clamav/files/clamav-0.99.3-fix-fd-leaks-in-cli_scanscript.patch
@@ -0,0 +1,132 @@
+Author: Manuel Mausz <manuel-clamav@mausz.at>
+
+http://lists.clamav.net/pipermail/clamav-users/2018-January/005687.html
+
+--- clamav-0.99.3/libclamav/scanners.c.orig 2018-01-26 14:35:23.299386703 +0100
++++ clamav-0.99.3/libclamav/scanners.c 2018-01-26 14:47:44.422451335 +0100
+@@ -1342,39 +1342,35 @@
+ return CL_CLEAN;
+ }
+
+- /* dump to disk only if explicitly asked to
+- * or if necessary to check relative offsets,
+- * otherwise we can process just in-memory */
+- if(ctx->engine->keeptmp || (troot && troot->ac_reloff_num > 0)) {
+- if((ret = cli_gentempfd(ctx->engine->tmpdir, &tmpname, &ofd))) {
+- cli_dbgmsg("cli_scanscript: Can't generate temporary file/descriptor\n");
+- return ret;
+- }
+- if (ctx->engine->keeptmp)
+- cli_dbgmsg("cli_scanscript: saving normalized file to %s\n", tmpname);
+- }
+-
+ if(!(normalized = cli_malloc(SCANBUFF + maxpatlen))) {
+ cli_dbgmsg("cli_scanscript: Unable to malloc %u bytes\n", SCANBUFF);
+- free(tmpname);
+ return CL_EMEM;
+ }
+-
+ text_normalize_init(&state, normalized, SCANBUFF + maxpatlen);
+- ret = CL_CLEAN;
+-
+
+ if ((ret = cli_ac_initdata(&tmdata, troot?troot->ac_partsigs:0, troot?troot->ac_lsigs:0, troot?troot->ac_reloff_num:0, CLI_DEFAULT_AC_TRACKLEN))) {
+- free(tmpname);
++ free(normalized);
+ return ret;
+ }
+
+ if ((ret = cli_ac_initdata(&gmdata, groot->ac_partsigs, groot->ac_lsigs, groot->ac_reloff_num, CLI_DEFAULT_AC_TRACKLEN))) {
+ cli_ac_freedata(&tmdata);
+- free(tmpname);
++ free(normalized);
+ return ret;
+ }
+
++ /* dump to disk only if explicitly asked to
++ * or if necessary to check relative offsets,
++ * otherwise we can process just in-memory */
++ if(ctx->engine->keeptmp || (troot && troot->ac_reloff_num > 0)) {
++ if((ret = cli_gentempfd(ctx->engine->tmpdir, &tmpname, &ofd))) {
++ cli_dbgmsg("cli_scanscript: Can't generate temporary file/descriptor\n");
++ goto done;
++ }
++ if (ctx->engine->keeptmp)
++ cli_dbgmsg("cli_scanscript: saving normalized file to %s\n", tmpname);
++ }
++
+ mdata[0] = &tmdata;
+ mdata[1] = &gmdata;
+
+@@ -1388,9 +1384,8 @@
+
+ if (write(ofd, state.out, state.out_pos) == -1) {
+ cli_errmsg("cli_scanscript: can't write to file %s\n",tmpname);
+- close(ofd);
+- free(tmpname);
+- return CL_EWRITE;
++ ret = CL_EWRITE;
++ goto done;
+ }
+ text_normalize_reset(&state);
+ }
+@@ -1409,11 +1404,6 @@
+ funmap(*ctx->fmap);
+ }
+ *ctx->fmap = map;
+-
+- /* If we aren't keeping temps, delete the normalized file after scan. */
+- if(!(ctx->engine->keeptmp))
+- if (cli_unlink(tmpname)) ret = CL_EUNLINK;
+-
+ } else {
+ /* Since the above is moderately costly all in all,
+ * do the old stuff if there's no relative offsets. */
+@@ -1421,11 +1411,8 @@
+ if (troot) {
+ cli_targetinfo(&info, 7, map);
+ ret = cli_ac_caloff(troot, &tmdata, &info);
+- if (ret) {
+- cli_ac_freedata(&tmdata);
+- free(tmpname);
+- return ret;
+- }
++ if (ret)
++ goto done;
+ }
+
+ while(1) {
+@@ -1466,13 +1453,6 @@
+
+ }
+
+- if(ctx->engine->keeptmp) {
+- free(tmpname);
+- if (ofd >= 0)
+- close(ofd);
+- }
+- free(normalized);
+-
+ if(ret != CL_VIRUS || SCAN_ALL) {
+ if ((ret = cli_exp_eval(ctx, troot, &tmdata, NULL, NULL)) == CL_VIRUS)
+ viruses_found++;
+@@ -1481,9 +1461,19 @@
+ viruses_found++;
+ }
+
++done:
++ free(normalized);
+ cli_ac_freedata(&tmdata);
+ cli_ac_freedata(&gmdata);
+
++ if (ofd != -1)
++ close(ofd);
++ if (tmpname != NULL) {
++ if (!ctx->engine->keeptmp)
++ if (cli_unlink(tmpname)) ret = CL_EUNLINK;
++ free(tmpname);
++ }
++
+ if (SCAN_ALL && viruses_found)
+ return CL_VIRUS;
+