]> git.pld-linux.org Git - packages/clamav.git/blame - clamav-0.99.2-temp-cleanup.patch
- fix tmp files cleaning
[packages/clamav.git] / clamav-0.99.2-temp-cleanup.patch
CommitLineData
e03286eb
AM
1https://github.com/vrtadmin/clamav-devel/commit/f5bc94cf01e6a19d5255c0e5f9a5bc2336f5a2b1
2backported (re-merge). See also:
3
4 - https://bugzilla.clamav.net/show_bug.cgi?id=11549
5 - https://github.com/e2guardian/e2guardian/issues/159
6
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 @@
10 return CL_CLEAN;
11 }
12
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");
19- return ret;
20- }
21- if (ctx->engine->keeptmp)
22- cli_dbgmsg("cli_scanscript: saving normalized file to %s\n", tmpname);
23- }
24-
25 if(!(normalized = cli_malloc(SCANBUFF + maxpatlen))) {
26 cli_dbgmsg("cli_scanscript: Unable to malloc %u bytes\n", SCANBUFF);
27- free(tmpname);
28 return CL_EMEM;
29 }
30-
31 text_normalize_init(&state, normalized, SCANBUFF + maxpatlen);
32- ret = CL_CLEAN;
33-
34
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))) {
36- free(tmpname);
37- return ret;
38+ free(normalized);
39+ return ret;
40 }
41
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);
44- free(tmpname);
45- return ret;
46+ cli_ac_freedata(&tmdata);
47+ free(normalized);
48+ return ret;
49+ }
50+
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");
57+ goto done;
58+ }
59+ if (ctx->engine->keeptmp)
60+ cli_dbgmsg("cli_scanscript: saving normalized file to %s\n", tmpname);
61 }
62
63 mdata[0] = &tmdata;
64@@ -1387,10 +1383,9 @@
65 map_off += written;
66
67 if (write(ofd, state.out, state.out_pos) == -1) {
68- cli_errmsg("cli_scanscript: can't write to file %s\n",tmpname);
69- close(ofd);
70- free(tmpname);
71- return CL_EWRITE;
72+ cli_errmsg("cli_scanscript: can't write to file %s\n",tmpname);
73+ ret = CL_EWRITE;
74+ goto done;
75 }
76 text_normalize_reset(&state);
77 }
78@@ -1409,11 +1404,6 @@
79 funmap(*ctx->fmap);
80 }
81 *ctx->fmap = map;
82-
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;
86-
87 } else {
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 @@
91 if (troot) {
92 cli_targetinfo(&info, 7, map);
93 ret = cli_ac_caloff(troot, &tmdata, &info);
94- if (ret) {
95- cli_ac_freedata(&tmdata);
96- free(tmpname);
97- return ret;
98- }
99+ if (ret)
100+ goto done;
101 }
102
103 while(1) {
104@@ -1466,13 +1453,6 @@
105
106 }
107
108- if(ctx->engine->keeptmp) {
109- free(tmpname);
110- if (ofd >= 0)
111- close(ofd);
112- }
113- free(normalized);
114-
115 if(ret != CL_VIRUS || SCAN_ALL) {
116 if ((ret = cli_exp_eval(ctx, troot, &tmdata, NULL, NULL)) == CL_VIRUS)
117 viruses_found++;
118@@ -1481,9 +1461,19 @@
119 viruses_found++;
120 }
121
122+done:
123+ free(normalized);
124 cli_ac_freedata(&tmdata);
125 cli_ac_freedata(&gmdata);
126
127+ if (ofd != -1)
128+ close(ofd);
129+ if (tmpname != NULL) {
130+ if (!ctx->engine->keeptmp)
131+ cli_unlink(tmpname);
132+ free(tmpname);
133+ }
134+
135 if (SCAN_ALL && viruses_found)
136 return CL_VIRUS;
137
This page took 0.201006 seconds and 4 git commands to generate.