Only create rfc2397 tmp directory when needed

HTML normalization creates a tmp directory for storing rfc2397 style
links.  The vast majority of html does not make use of rfc2397 and thus
an excess of empty tmp directories are generated.  This commit alters
behavior to only create the rfc2397 directory when required if it does
not already exist.
pull/124/head
Micah Snyder 5 years ago
parent 9b9999d778
commit c545cad161
  1. 17
      libclamav/htmlnorm.c
  2. 4
      libclamav/scanners.c

@ -697,12 +697,6 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
tag_args.value = NULL;
tag_args.contents = NULL;
if (dirname) {
snprintf(filename, 1024, "%s" PATHSEP "rfc2397", dirname);
if (mkdir(filename, 0700) && errno != EEXIST) {
file_buff_o2 = file_buff_text = NULL;
goto abort;
}
file_buff_o2 = (file_buff_t *)cli_malloc(sizeof(file_buff_t));
if (!file_buff_o2) {
cli_errmsg("cli_html_normalise: Unable to allocate memory for file_buff_o2\n");
@ -1611,6 +1605,8 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
break;
case HTML_RFC2397_INIT:
if (dirname) {
STATBUF statbuf;
if (NULL != file_tmp_o1) {
if (file_tmp_o1->fd != -1) {
html_output_flush(file_tmp_o1);
@ -1625,7 +1621,16 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
cli_errmsg("cli_html_normalise: Unable to allocate memory for file_tmp_o1\n");
goto abort;
}
/* Create rfc2397 directory if it doesn't already exist */
snprintf(filename, 1024, "%s" PATHSEP "rfc2397", dirname);
if (LSTAT(filename, &statbuf) == -1) {
if (mkdir(filename, 0700) && errno != EEXIST) {
cli_errmsg("Failed to create directory: %s\n", dirname);
goto abort;
}
}
tmp_file = cli_gentemp(filename);
if (!tmp_file) {
goto abort;

@ -2031,6 +2031,10 @@ static cl_error_t cli_scanhtml(cli_ctx *ctx)
if (ret == CL_CLEAN || (ret == CL_VIRUS && SCAN_ALLMATCHES)) {
snprintf(fullname, 1024, "%s" PATHSEP "rfc2397", tempname);
ret = cli_magic_scan_dir(fullname, ctx);
if (CL_EOPEN == ret) {
/* If the directory doesn't exist, that's fine */
ret = CL_CLEAN;
}
}
if (!ctx->engine->keeptmp)

Loading…
Cancel
Save