From 26770bc5690e950767e3dffc70b5231937e0a2ca Mon Sep 17 00:00:00 2001 From: Till Kamppeter Date: Fri, 12 Feb 2021 17:43:32 +0100 Subject: [PATCH] libcupsfilters: Fixed several temporary file leaks --- cupsfilters/ghostscript.c | 3 +++ cupsfilters/imagetopdf.c | 3 +++ cupsfilters/imagetops.c | 3 +++ cupsfilters/imagetoraster.c | 5 +++++ cupsfilters/pclmtoraster.cxx | 4 ++++ cupsfilters/pdftops.c | 6 ++++-- cupsfilters/ppdgenerator.c | 4 ++++ 7 files changed, 26 insertions(+), 2 deletions(-) diff --git a/cupsfilters/ghostscript.c b/cupsfilters/ghostscript.c index 2ee29eb4a..16bf79dc2 100644 --- a/cupsfilters/ghostscript.c +++ b/cupsfilters/ghostscript.c @@ -1152,6 +1152,9 @@ out: free(envp[i]); if (fp) fclose(fp); + if (filename) + /* Remove name of temp file*/ + unlink(filename); if (gs_args) { while ((tmp = cupsArrayFirst(gs_args)) != NULL) { cupsArrayRemove(gs_args,tmp); diff --git a/cupsfilters/imagetopdf.c b/cupsfilters/imagetopdf.c index 2215eea99..19b30e526 100644 --- a/cupsfilters/imagetopdf.c +++ b/cupsfilters/imagetopdf.c @@ -806,6 +806,7 @@ imagetopdf(int inputfd, /* I - File descriptor input stream */ "imagetopdf: Unable to open temporary file."); } + unlink(tempfile); return (1); } } @@ -823,6 +824,8 @@ imagetopdf(int inputfd, /* I - File descriptor input stream */ } fclose(fp); + if (!inputseekable) + unlink(tempfile); return (1); } diff --git a/cupsfilters/imagetops.c b/cupsfilters/imagetops.c index c40871451..bbef8d708 100644 --- a/cupsfilters/imagetops.c +++ b/cupsfilters/imagetops.c @@ -216,6 +216,7 @@ imagetops(int inputfd, /* I - File descriptor input stream */ "imagetops: Unable to open temporary file."); } + unlink(tempfile); return (1); } } @@ -234,6 +235,8 @@ imagetops(int inputfd, /* I - File descriptor input stream */ fclose(inputfp); + if (!inputseekable) + unlink(tempfile); return (1); } diff --git a/cupsfilters/imagetoraster.c b/cupsfilters/imagetoraster.c index 3e020148e..f541ec37c 100644 --- a/cupsfilters/imagetoraster.c +++ b/cupsfilters/imagetoraster.c @@ -338,6 +338,7 @@ imagetoraster(int inputfd, /* I - File descriptor input stream */ "imagetoraster: Unable to open temporary file."); } + unlink(tempfile); return (1); } } @@ -502,6 +503,8 @@ imagetoraster(int inputfd, /* I - File descriptor input stream */ log(ld, FILTER_LOGLEVEL_DEBUG, "imagetoraster: %s", cupsRasterErrorString()); } + if (!inputseekable) + unlink(tempfile); return (1); } @@ -632,6 +635,8 @@ imagetoraster(int inputfd, /* I - File descriptor input stream */ if (log) log(ld, FILTER_LOGLEVEL_DEBUG, "imagetoraster: Colorspace %d not supported.", header.cupsColorSpace); + if (!inputseekable) + unlink(tempfile); return(1); break; } diff --git a/cupsfilters/pclmtoraster.cxx b/cupsfilters/pclmtoraster.cxx index 4908256b4..ef4d04620 100644 --- a/cupsfilters/pclmtoraster.cxx +++ b/cupsfilters/pclmtoraster.cxx @@ -1108,6 +1108,7 @@ pclmtoraster(int inputfd, /* I - File descriptor input stream */ if (parseOpts(data, &pclmtoraster_data) != 0) { delete(pdf); + unlink(tempfile); return (1); } @@ -1121,6 +1122,7 @@ pclmtoraster(int inputfd, /* I - File descriptor input stream */ "pclmtoraster: Specified color format is not supported: %s", strerror(errno)); delete(pdf); + unlink(tempfile); if (pclmtoraster_data.ppd != NULL) ppdClose(pclmtoraster_data.ppd); return (1); } @@ -1150,6 +1152,7 @@ pclmtoraster(int inputfd, /* I - File descriptor input stream */ "pclmtoraster: Can't open raster stream: %s", strerror(errno)); delete(pdf); + unlink(tempfile); if (pclmtoraster_data.ppd != NULL) ppdClose(pclmtoraster_data.ppd); return (1); } @@ -1175,6 +1178,7 @@ pclmtoraster(int inputfd, /* I - File descriptor input stream */ cupsRasterClose(raster); delete pdf; + unlink(tempfile); if (pclmtoraster_data.ppd != NULL) ppdClose(pclmtoraster_data.ppd); return 0; } diff --git a/cupsfilters/pdftops.c b/cupsfilters/pdftops.c index 2edbf931c..9615b8b69 100644 --- a/cupsfilters/pdftops.c +++ b/cupsfilters/pdftops.c @@ -364,7 +364,10 @@ pdftops(int inputfd, /* I - File descriptor input stream */ */ if (is_empty(filename, log, ld)) + { + unlink(tempfile); return 0; + } /* * Read out copy counts and collate setting passed over by pdftopdf @@ -1683,8 +1686,7 @@ pdftops(int inputfd, /* I - File descriptor input stream */ close(outputfd); - //if (tempfile[0]) - //unlink(tempfile); + unlink(tempfile); return (exit_status); } diff --git a/cupsfilters/ppdgenerator.c b/cupsfilters/ppdgenerator.c index ebc2ee1c0..8fc06aa9c 100644 --- a/cupsfilters/ppdgenerator.c +++ b/cupsfilters/ppdgenerator.c @@ -777,7 +777,11 @@ load_opt_strings_catalog(const char *location, cups_array_t *options) return; if ((fp = cupsFileOpen(filename, "r")) == NULL) + { + if (filename == tmpfile) + unlink(filename); return; + } while (cupsFileGets(fp, line, sizeof(line)) || (part = 10)) { /* Find a pair of quotes delimiting a string in each line -- 2.47.3