1 https://github.com/vrtadmin/clamav-devel/commit/f5bc94cf01e6a19d5255c0e5f9a5bc2336f5a2b1
2 backported (re-merge). See also:
4 - https://bugzilla.clamav.net/show_bug.cgi?id=11549
5 - https://github.com/e2guardian/e2guardian/issues/159
7 --- clamav-0.99.2/libclamav/scanners.c 2016-04-22 17:02:19.000000000 +0200
8 +++ clamav-0.99.2/libclamav/scanners.c.temp-cleanup 2017-11-17 00:59:14.295670694 +0100
9 @@ -1342,37 +1342,33 @@
13 - /* dump to disk only if explicitly asked to
14 - * or if necessary to check relative offsets,
15 - * otherwise we can process just in-memory */
16 - if(ctx->engine->keeptmp || (troot && troot->ac_reloff_num > 0)) {
17 - if((ret = cli_gentempfd(ctx->engine->tmpdir, &tmpname, &ofd))) {
18 - cli_dbgmsg("cli_scanscript: Can't generate temporary file/descriptor\n");
21 - if (ctx->engine->keeptmp)
22 - cli_dbgmsg("cli_scanscript: saving normalized file to %s\n", tmpname);
25 if(!(normalized = cli_malloc(SCANBUFF + maxpatlen))) {
26 cli_dbgmsg("cli_scanscript: Unable to malloc %u bytes\n", SCANBUFF);
31 text_normalize_init(&state, normalized, SCANBUFF + maxpatlen);
35 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))) {
42 if ((ret = cli_ac_initdata(&gmdata, groot->ac_partsigs, groot->ac_lsigs, groot->ac_reloff_num, CLI_DEFAULT_AC_TRACKLEN))) {
43 - cli_ac_freedata(&tmdata);
46 + cli_ac_freedata(&tmdata);
51 + /* dump to disk only if explicitly asked to
52 + * or if necessary to check relative offsets,
53 + * otherwise we can process just in-memory */
54 + if(ctx->engine->keeptmp || (troot && troot->ac_reloff_num > 0)) {
55 + if((ret = cli_gentempfd(ctx->engine->tmpdir, &tmpname, &ofd))) {
56 + cli_dbgmsg("cli_scanscript: Can't generate temporary file/descriptor\n");
59 + if (ctx->engine->keeptmp)
60 + cli_dbgmsg("cli_scanscript: saving normalized file to %s\n", tmpname);
64 @@ -1387,10 +1383,9 @@
67 if (write(ofd, state.out, state.out_pos) == -1) {
68 - cli_errmsg("cli_scanscript: can't write to file %s\n",tmpname);
72 + cli_errmsg("cli_scanscript: can't write to file %s\n",tmpname);
76 text_normalize_reset(&state);
78 @@ -1409,11 +1404,6 @@
83 - /* If we aren't keeping temps, delete the normalized file after scan. */
84 - if(!(ctx->engine->keeptmp))
85 - if (cli_unlink(tmpname)) ret = CL_EUNLINK;
88 /* Since the above is moderately costly all in all,
89 * do the old stuff if there's no relative offsets. */
90 @@ -1421,11 +1411,8 @@
92 cli_targetinfo(&info, 7, map);
93 ret = cli_ac_caloff(troot, &tmdata, &info);
95 - cli_ac_freedata(&tmdata);
104 @@ -1466,13 +1453,6 @@
108 - if(ctx->engine->keeptmp) {
115 if(ret != CL_VIRUS || SCAN_ALL) {
116 if ((ret = cli_exp_eval(ctx, troot, &tmdata, NULL, NULL)) == CL_VIRUS)
118 @@ -1481,9 +1461,19 @@
124 cli_ac_freedata(&tmdata);
125 cli_ac_freedata(&gmdata);
129 + if (tmpname != NULL) {
130 + if (!ctx->engine->keeptmp)
131 + cli_unlink(tmpname);
135 if (SCAN_ALL && viruses_found)