From 5722ebc5823381ee57c525cbc0d4dc627009979d Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 1 Dec 2017 16:25:39 +0100 Subject: Fix 698787: avoid using "system()" to copy files. --- platform/x11/x11_main.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/platform/x11/x11_main.c b/platform/x11/x11_main.c index fe2daa87..edbb9fa8 100644 --- a/platform/x11/x11_main.c +++ b/platform/x11/x11_main.c @@ -317,13 +317,38 @@ void winreplacefile(char *source, char *target) void wincopyfile(char *source, char *target) { - char *buf = malloc(strlen(source)+strlen(target)+5); - if (buf) + FILE *in, *out; + char buf[32 << 10]; + int n; + + in = fopen(source, "rb"); + if (!in) + { + winerror(&gapp, "cannot open source file for copying"); + return; + } + out = fopen(target, "wb"); + if (!out) + { + winerror(&gapp, "cannot open target file for copying"); + fclose(in); + return; + } + + for (;;) { - sprintf(buf, "cp %s %s", source, target); - system(buf); - free(buf); + n = fread(buf, 1, sizeof buf, in); + fwrite(buf, 1, n, out); + if (n < sizeof buf) + { + if (ferror(in)) + winerror(&gapp, "cannot read data from source file"); + break; + } } + + fclose(out); + fclose(in); } void cleanup(pdfapp_t *app) -- cgit v1.2.3