1 From f4f50ceea8e8852b8c3ac73f5807d8b54b735c3e Mon Sep 17 00:00:00 2001
2 From: Chris Liddell <chris.liddell@artifex.com>
3 Date: Tue, 21 Aug 2018 20:17:05 +0100
4 Subject: [PATCH 5/5] Bug 699657: properly apply file permissions to .tempfile
7 Upstream-Status: Backport [git://git.ghostscript.com/ghostpdl.git]
9 Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
11 psi/zfile.c | 20 ++++++++++++++++++--
12 1 file changed, 18 insertions(+), 2 deletions(-)
14 diff --git a/psi/zfile.c b/psi/zfile.c
15 index a0acd5a..19996b0 100644
18 @@ -134,7 +134,7 @@ check_file_permissions_reduced(i_ctx_t *i_ctx_p, const char *fname, int len,
19 /* we're protecting arbitrary file system accesses, not Postscript device accesses.
20 * Although, note that %pipe% is explicitly checked for and disallowed elsewhere
22 - if (iodev != iodev_default(imemory)) {
23 + if (iodev && iodev != iodev_default(imemory)) {
27 @@ -734,7 +734,23 @@ ztempfile(i_ctx_t *i_ctx_p)
30 if (gp_file_name_is_absolute(pstr, strlen(pstr))) {
31 - if (check_file_permissions(i_ctx_p, pstr, strlen(pstr),
32 + int plen = strlen(pstr);
33 + const char *sep = gp_file_name_separator();
35 + int seplen = strlen(sep);
37 + return_error(gs_error_Fatal);
39 + /* strip off the file name prefix, leave just the directory name
40 + * so we can check if we are allowed to write to it
42 + for ( ; plen >=0; plen--) {
43 + if (pstr[plen] == sep[0])
46 + memcpy(fname, pstr, plen);
48 + if (check_file_permissions(i_ctx_p, fname, strlen(fname),
49 NULL, "PermitFileWriting") < 0) {
50 code = gs_note_error(gs_error_invalidfileaccess);