|
|
bd82b2 |
From: Chris Liddell <chris.liddell@artifex.com>
|
|
|
bd82b2 |
Date: Sat, 1 Sep 2018 16:50:05 +0000 (+0100)
|
|
|
bd82b2 |
Subject: Bug 699658(related): Move recording of temp file names into C
|
|
|
bd82b2 |
|
|
|
bd82b2 |
Bug 699658(related): Move recording of temp file names into C
|
|
|
bd82b2 |
|
|
|
bd82b2 |
When we successfully create a temporary file from Postscript, either doing so
|
|
|
bd82b2 |
when SAFER is not in force, or when SAFER is in force, and creating it in
|
|
|
bd82b2 |
a write permitted directory, we record the file name so we can later delete
|
|
|
bd82b2 |
the file, even is SAFER has been engaged, or if the PermitWriting list has
|
|
|
bd82b2 |
changed to no longer the directory in question.
|
|
|
bd82b2 |
|
|
|
bd82b2 |
Previously the recording of the name was done in Postscript, even though the
|
|
|
bd82b2 |
checking was done in C.
|
|
|
bd82b2 |
|
|
|
bd82b2 |
This moves the recording of the names to C, meaning we can remove the Postscript
|
|
|
bd82b2 |
redefinitions of .tempfile and deletfile, and make the dictionary in question
|
|
|
bd82b2 |
noaccess.
|
|
|
bd82b2 |
|
|
|
bd82b2 |
Also, tidy up the adding of the temporary file directory to the list of
|
|
|
bd82b2 |
permitted directories, and include the list in all of the categories
|
|
|
bd82b2 |
(PermitFileWriting, PermitFileReading and PermitFileControl) - it was only
|
|
|
bd82b2 |
previously adding to writing.
|
|
|
bd82b2 |
|
|
|
bd82b2 |
https://git.ghostscript.com/?p=ghostpdl.git;a=commit;h=0704d18b10314d701a522ad6c16718e0b8e199b7
|
|
|
bd82b2 |
---
|
|
|
bd82b2 |
|
|
|
bd82b2 |
diff -up ghostscript-9.07/psi/int.mak.bz1661210 ghostscript-9.07/psi/int.mak
|
|
|
bd82b2 |
--- ghostscript-9.07/psi/int.mak.bz1661210 2018-12-20 17:38:21.683312408 +0100
|
|
|
bd82b2 |
+++ ghostscript-9.07/psi/int.mak 2018-12-20 17:38:40.583083097 +0100
|
|
|
bd82b2 |
@@ -330,7 +330,7 @@ $(PSOBJ)zfile.$(OBJ) : $(PSSRC)zfile.c $
|
|
|
bd82b2 |
$(memory__h) $(string__h) $(unistd__h) $(stat__h) $(gp_h) $(gpmisc_h)\
|
|
|
bd82b2 |
$(gscdefs_h) $(gsfname_h) $(gsstruct_h) $(gsutil_h) $(gxalloc_h) $(gxiodev_h)\
|
|
|
bd82b2 |
$(dstack_h) $(estack_h) $(files_h)\
|
|
|
bd82b2 |
- $(ialloc_h) $(idict_h) $(ilevel_h) $(iname_h) $(iutil_h)\
|
|
|
bd82b2 |
+ $(ialloc_h) $(idict_h) $(iddict_h) $(ilevel_h) $(iname_h) $(iutil_h)\
|
|
|
bd82b2 |
$(isave_h) $(main_h) $(sfilter_h) $(stream_h) $(strimpl_h) $(store_h)\
|
|
|
bd82b2 |
$(zfile_h)
|
|
|
bd82b2 |
$(PSCC) $(PSO_)zfile.$(OBJ) $(C_) $(PSSRC)zfile.c
|
|
|
bd82b2 |
diff -up ghostscript-9.07/psi/zfile.c.bz1661210 ghostscript-9.07/psi/zfile.c
|
|
|
bd82b2 |
--- ghostscript-9.07/psi/zfile.c.bz1661210 2018-12-20 17:39:09.975726450 +0100
|
|
|
bd82b2 |
+++ ghostscript-9.07/psi/zfile.c 2018-12-20 17:44:50.698592208 +0100
|
|
|
bd82b2 |
@@ -35,6 +35,7 @@
|
|
|
bd82b2 |
#include "iname.h"
|
|
|
bd82b2 |
#include "isave.h" /* for restore */
|
|
|
bd82b2 |
#include "idict.h"
|
|
|
bd82b2 |
+#include "iddict.h"
|
|
|
bd82b2 |
#include "iutil.h"
|
|
|
bd82b2 |
#include "stream.h"
|
|
|
bd82b2 |
#include "strimpl.h"
|
|
|
bd82b2 |
@@ -290,6 +291,28 @@ file_is_tempfile(i_ctx_t *i_ctx_p, const
|
|
|
bd82b2 |
return true;
|
|
|
bd82b2 |
}
|
|
|
bd82b2 |
|
|
|
bd82b2 |
+static int
|
|
|
bd82b2 |
+record_file_is_tempfile(i_ctx_t *i_ctx_p, const uchar *fname, int len, bool add)
|
|
|
bd82b2 |
+{
|
|
|
bd82b2 |
+ ref *SAFETY;
|
|
|
bd82b2 |
+ ref *tempfiles;
|
|
|
bd82b2 |
+ ref kname, bref;
|
|
|
bd82b2 |
+ int code = 0;
|
|
|
bd82b2 |
+
|
|
|
bd82b2 |
+ if (dict_find_string(systemdict, "SAFETY", &SAFETY) <= 0 ||
|
|
|
bd82b2 |
+ dict_find_string(SAFETY, "tempfiles", &tempfiles) <= 0) {
|
|
|
bd82b2 |
+ return 0;
|
|
|
bd82b2 |
+ }
|
|
|
bd82b2 |
+ if ((code = name_ref(imemory, fname, len, &kname, 1)) < 0) {
|
|
|
bd82b2 |
+ return code;
|
|
|
bd82b2 |
+ }
|
|
|
bd82b2 |
+ make_bool(&bref, true);
|
|
|
bd82b2 |
+ if (add)
|
|
|
bd82b2 |
+ return idict_put(tempfiles, &kname, &bref;;
|
|
|
bd82b2 |
+ else
|
|
|
bd82b2 |
+ return idict_undef(tempfiles, &kname);
|
|
|
bd82b2 |
+}
|
|
|
bd82b2 |
+
|
|
|
bd82b2 |
/* ------ Level 2 extensions ------ */
|
|
|
bd82b2 |
|
|
|
bd82b2 |
/* <string> deletefile - */
|
|
|
bd82b2 |
@@ -299,17 +322,22 @@ zdeletefile(i_ctx_t *i_ctx_p)
|
|
|
bd82b2 |
os_ptr op = osp;
|
|
|
bd82b2 |
gs_parsed_file_name_t pname;
|
|
|
bd82b2 |
int code = parse_real_file_name(op, &pname, imemory, "deletefile");
|
|
|
bd82b2 |
+ bool is_temp = false;
|
|
|
bd82b2 |
|
|
|
bd82b2 |
if (code < 0)
|
|
|
bd82b2 |
return code;
|
|
|
bd82b2 |
if (pname.iodev == iodev_default(imemory)) {
|
|
|
bd82b2 |
if ((code = check_file_permissions(i_ctx_p, pname.fname, pname.len,
|
|
|
bd82b2 |
pname.iodev, "PermitFileControl")) < 0 &&
|
|
|
bd82b2 |
- !file_is_tempfile(i_ctx_p, op->value.bytes, r_size(op))) {
|
|
|
bd82b2 |
+ !(is_temp = file_is_tempfile(i_ctx_p, op->value.bytes, r_size(op)))) {
|
|
|
bd82b2 |
return code;
|
|
|
bd82b2 |
}
|
|
|
bd82b2 |
}
|
|
|
bd82b2 |
code = (*pname.iodev->procs.delete_file)(pname.iodev, pname.fname);
|
|
|
bd82b2 |
+
|
|
|
bd82b2 |
+ if (code >= 0 && is_temp)
|
|
|
bd82b2 |
+ code = record_file_is_tempfile(i_ctx_p, (unsigned char *)pname.fname, strlen(pname.fname), false);
|
|
|
bd82b2 |
+
|
|
|
bd82b2 |
gs_free_file_name(&pname, "deletefile");
|
|
|
bd82b2 |
if (code < 0)
|
|
|
bd82b2 |
return code;
|
|
|
bd82b2 |
@@ -757,6 +785,7 @@ ztempfile(i_ctx_t *i_ctx_p)
|
|
|
bd82b2 |
}
|
|
|
bd82b2 |
make_string(op - 1, a_readonly | icurrent_space, fnlen, sbody);
|
|
|
bd82b2 |
make_stream_file(op, s, fmode);
|
|
|
bd82b2 |
+ code = record_file_is_tempfile(i_ctx_p, (unsigned char *)fname, fnlen, true);
|
|
|
bd82b2 |
return code;
|
|
|
bd82b2 |
}
|
|
|
bd82b2 |
|
|
|
bd82b2 |
diff -up ghostscript-9.07/Resource/Init/gs_init.ps.bz1661210 ghostscript-9.07/Resource/Init/gs_init.ps
|
|
|
bd82b2 |
--- ghostscript-9.07/Resource/Init/gs_init.ps.bz1661210 2018-12-20 17:33:51.469591104 +0100
|
|
|
bd82b2 |
+++ ghostscript-9.07/Resource/Init/gs_init.ps 2018-12-20 17:35:36.694314341 +0100
|
|
|
bd82b2 |
@@ -2030,15 +2030,30 @@ systemdict /EPSBoundingBoxInit known { E
|
|
|
bd82b2 |
.currentglobal //true .setglobal
|
|
|
bd82b2 |
/SAFETY 2 dict
|
|
|
bd82b2 |
dup /safe //false put
|
|
|
bd82b2 |
- dup /tempfiles 10 dict readonly put
|
|
|
bd82b2 |
+ dup /tempfiles 10 dict noaccess put
|
|
|
bd82b2 |
readonly def
|
|
|
bd82b2 |
.setglobal
|
|
|
bd82b2 |
|
|
|
bd82b2 |
+/tempfilepaths
|
|
|
bd82b2 |
+[
|
|
|
bd82b2 |
+ (TMPDIR) getenv not
|
|
|
bd82b2 |
+ {
|
|
|
bd82b2 |
+ (TEMP) getenv not
|
|
|
bd82b2 |
+ {
|
|
|
bd82b2 |
+ (TMP) getenv not
|
|
|
bd82b2 |
+ {
|
|
|
bd82b2 |
+ (/temp) (/tmp)
|
|
|
bd82b2 |
+ } if
|
|
|
bd82b2 |
+ } if
|
|
|
bd82b2 |
+ } if
|
|
|
bd82b2 |
+] def
|
|
|
bd82b2 |
+
|
|
|
bd82b2 |
/.locksafe {
|
|
|
bd82b2 |
SAFETY /safe get not {
|
|
|
bd82b2 |
<<
|
|
|
bd82b2 |
/PermitFileReading [
|
|
|
bd82b2 |
currentuserparams /PermitFileReading get aload pop
|
|
|
bd82b2 |
+ //tempfilepaths aload pop
|
|
|
bd82b2 |
/FONTPATH .systemvar (*) .generate_dir_list_templates
|
|
|
bd82b2 |
% Library files :
|
|
|
bd82b2 |
/LIBPATH .systemvar (*) .generate_dir_list_templates
|
|
|
bd82b2 |
@@ -2056,16 +2071,11 @@ readonly def
|
|
|
bd82b2 |
]
|
|
|
bd82b2 |
/PermitFileWriting [
|
|
|
bd82b2 |
currentuserparams /PermitFileWriting get aload pop
|
|
|
bd82b2 |
- (TMPDIR) getenv not
|
|
|
bd82b2 |
- {
|
|
|
bd82b2 |
- (TEMP) getenv not
|
|
|
bd82b2 |
- {
|
|
|
bd82b2 |
- (TMP) getenv not
|
|
|
bd82b2 |
- {
|
|
|
bd82b2 |
- (/temp) (/tmp)
|
|
|
bd82b2 |
- } if
|
|
|
bd82b2 |
- } if
|
|
|
bd82b2 |
- } if
|
|
|
bd82b2 |
+ //tempfilepaths aload pop
|
|
|
bd82b2 |
+ ]
|
|
|
bd82b2 |
+ /PermitFileControl [
|
|
|
bd82b2 |
+ currentuserparams /PermitFileControl get aload pop
|
|
|
bd82b2 |
+ //tempfilepaths aload pop
|
|
|
bd82b2 |
]
|
|
|
bd82b2 |
/LockFilePermissions //true
|
|
|
bd82b2 |
>> setuserparams
|
|
|
bd82b2 |
@@ -2082,6 +2092,8 @@ readonly def
|
|
|
bd82b2 |
//SAFETY /safe //true .forceput % overrides readonly
|
|
|
bd82b2 |
} .bind executeonly odef
|
|
|
bd82b2 |
|
|
|
bd82b2 |
+currentdict /tempfilepaths undef
|
|
|
bd82b2 |
+
|
|
|
bd82b2 |
/.setsafe
|
|
|
bd82b2 |
{
|
|
|
bd82b2 |
SAFETY /safe get not {
|
|
|
bd82b2 |
@@ -2095,30 +2107,6 @@ readonly def
|
|
|
bd82b2 |
.locksafe
|
|
|
bd82b2 |
} .bind executeonly odef
|
|
|
bd82b2 |
|
|
|
bd82b2 |
-/deletefile {
|
|
|
bd82b2 |
- dup { deletefile } stopped {
|
|
|
bd82b2 |
- pop //deletefile $error /errorname get signalerror
|
|
|
bd82b2 |
- } {
|
|
|
bd82b2 |
- % deletefile succeeded. Remove from tempfile list if present
|
|
|
bd82b2 |
- //SAFETY /tempfiles get exch cvn 2 copy known {
|
|
|
bd82b2 |
- .forceundef
|
|
|
bd82b2 |
- } {
|
|
|
bd82b2 |
- pop pop
|
|
|
bd82b2 |
- }
|
|
|
bd82b2 |
- ifelse
|
|
|
bd82b2 |
- }
|
|
|
bd82b2 |
- ifelse
|
|
|
bd82b2 |
-} .bind executeonly odef
|
|
|
bd82b2 |
-
|
|
|
bd82b2 |
-% If a file is opened with .tempfile with SAFER not (yet) set,
|
|
|
bd82b2 |
-% the file can be deleted later, even if SAFER is set.
|
|
|
bd82b2 |
-/.tempfile {
|
|
|
bd82b2 |
- .tempfile % filename file
|
|
|
bd82b2 |
- //SAFETY /safe get not { % only add the filename if we're not yet safe
|
|
|
bd82b2 |
- //SAFETY /tempfiles get 2 .argindex //true .forceput
|
|
|
bd82b2 |
- } if
|
|
|
bd82b2 |
-} .bind executeonly odef
|
|
|
bd82b2 |
-
|
|
|
bd82b2 |
% If we are running in SAFER mode, lock things down
|
|
|
bd82b2 |
SAFER { .setsafe } if
|
|
|
bd82b2 |
|