From a48d39fe501169a1fa21590dfa8594f2e6b931f4 Mon Sep 17 00:00:00 2001 From: Pranav Batra Date: Fri, 13 Nov 2020 08:25:48 +0000 Subject: [PATCH] cups-filters: Fix foomatic-rip infinite loop If the foomatic rip command is not present in the PPD file, the foomatic rip filter runs cat by default to forward stdin to stdout. However, if input is provided through a file instead of stdin, then this file needs to be dup'd to stdin for the command to work properly. Also, the next file needs to be selected each time an input file is processed by calling strok_r in order to prevent an infinite loop. TEST=foomatic-rip --ppd=ppd.ppd file.pdf --- filter/foomatic-rip/foomaticrip.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/filter/foomatic-rip/foomaticrip.c b/filter/foomatic-rip/foomaticrip.c index 145982737..63d676e1a 100644 --- a/filter/foomatic-rip/foomaticrip.c +++ b/filter/foomatic-rip/foomaticrip.c @@ -1153,7 +1153,18 @@ int main(int argc, char** argv) when there is no postpipe) */ _log("Raw printing, executing \"cat %%s\"\n\n"); snprintf(tmp, 1024, "cat %s", postpipe->data); + if (strcasecmp(filename, "")) { + FILE *fh = fopen(filename, "r"); + if (!fh) { + _log("Failed to open \"%s\".\n", filename); + fclose(stdin); + } else { + dup2(fileno(fh), 0); + fclose(fh); + } + } run_system_process("raw-printer", tmp); + filename = strtok_r(NULL, " ", &p); continue; } -- 2.47.2