1 From 1f9a91c86bd56acf57826b9b0e020ebe1953e2ae Mon Sep 17 00:00:00 2001
2 From: Chris Liddell <chris.liddell@artifex.com>
3 Date: Thu, 4 Oct 2018 10:42:13 +0100
4 Subject: [PATCH 3/5] Bug 699832: add control over hiding error handlers.
6 With a previous commit changing error handling in SAFER so the handler gets
7 passed a name object (rather than executable object), it is less critical to
8 hide the error handlers.
10 This introduces a -dSAFERERRORS option to force only use of the default error
13 It also adds a .setsafererrors Postscript call, meaning a caller, without
14 -dSAFERERRORS, can create their own default error handlers (in errordict, as
15 normal), and then call .setsafererrors meaning their own handlers are always
18 With -dSAFERERRORS or after a call to .setsafererrors, .setsafererrors is
22 Upstream-Status: Backport [git://git.ghostscript.com/ghostpdl.git]
23 Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
25 Resource/Init/gs_init.ps | 42 +++++++++++++++++++++++++++++------------
26 psi/interp.c | 49 ++++++++++++++++++++++++++++--------------------
27 2 files changed, 59 insertions(+), 32 deletions(-)
29 diff --git a/Resource/Init/gs_init.ps b/Resource/Init/gs_init.ps
30 index bec307d..f952f32 100644
31 --- a/Resource/Init/gs_init.ps
32 +++ b/Resource/Init/gs_init.ps
33 @@ -188,6 +188,16 @@ currentdict /DELAYSAFER known { /DELAYSAFER //true def /NOSAFER //true def } if
34 currentdict /PARANOIDSAFER known or % PARANOIDSAFER is equivalent
39 +currentdict /NOSAFERERRORS known
44 + currentdict /SAFERERRORS known
47 currentdict /SHORTERRORS known /SHORTERRORS exch def
48 currentdict /TTYPAUSE known /TTYPAUSE exch def
49 currentdict /WRITESYSTEMDICT known /WRITESYSTEMDICT exch def
50 @@ -1123,12 +1133,23 @@ errordict begin
54 -% Put all the default handlers in gserrordict
56 -errordict {2 index 3 1 roll put} forall
58 -% remove the non-standard errors from errordict
59 +gserrordict /unknownerror errordict /unknownerror get put
60 errordict /unknownerror .undef
62 +/.SAFERERRORLIST ErrorNames def
65 +% Put all the requested handlers in gserrordict
68 + {dup errordict exch get 2 index 3 1 roll put} forall
70 + systemdict /.setsafeerrors .forceundef
71 + systemdict /.SAFERERRORLIST .forceundef
72 +} bind executeonly odef
74 +SAFERERRORS {.setsafererrors} if
76 % Define a stable private copy of handleerror that we will always use under
78 /.GShandleerror errordict /handleerror get def
79 @@ -1760,18 +1781,15 @@ currentdict /.runlibfile .undef
81 % Bind all the operators defined as procedures.
82 /.bindoperators % binds operators in currentdict
83 - { % Temporarily disable the typecheck error.
84 - errordict /typecheck 2 copy get
85 - errordict /typecheck { pop } put % pop the command
88 { dup type /operatortype eq
89 - { % This might be a real operator, so bind might cause a typecheck,
90 - % but we've made the error a no-op temporarily.
93 + % This might be a real operator, so bind might cause a typecheck
94 + {.bind} .internalstopped pop
100 DELAYBIND not { .bindoperators } if
102 diff --git a/psi/interp.c b/psi/interp.c
103 index 3dd5f7a..cd894f9 100644
106 @@ -662,27 +662,18 @@ again:
107 if (gs_errorname(i_ctx_p, code, &error_name) < 0)
108 return code; /* out-of-range error code! */
110 - /* If LockFilePermissions is true, we only refer to gserrordict, which
111 - * is not accessible to Postcript jobs
112 + /* We refer to gserrordict first, which is not accessible to Postcript jobs
113 + * If we're running with SAFERERRORS all the handlers are copied to gserrordict
114 + * so we'll always find the default one. If not SAFERERRORS, only gs specific
115 + * errors are in gserrordict.
117 - if (i_ctx_p->LockFilePermissions) {
118 - if (((dict_find_string(systemdict, "gserrordict", &perrordict) <= 0 ||
119 - dict_find(perrordict, &error_name, &epref) <= 0))
121 - return code; /* error name not in errordict??? */
125 - * For greater Adobe compatibility, only the standard PostScript errors
126 - * are defined in errordict; the rest are in gserrordict.
128 - if (dict_find_string(systemdict, "errordict", &perrordict) <= 0 ||
129 - (dict_find(perrordict, &error_name, &epref) <= 0 &&
130 - (dict_find_string(systemdict, "gserrordict", &perrordict) <= 0 ||
131 - dict_find(perrordict, &error_name, &epref) <= 0))
133 - return code; /* error name not in errordict??? */
135 + if (dict_find_string(systemdict, "gserrordict", &perrordict) <= 0 ||
136 + (dict_find(perrordict, &error_name, &epref) <= 0 &&
137 + (dict_find_string(systemdict, "errordict", &perrordict) <= 0 ||
138 + dict_find(perrordict, &error_name, &epref) <= 0))
140 + return code; /* error name not in errordict??? */
144 /* Push the error object on the operand stack if appropriate. */
145 @@ -695,6 +686,24 @@ again:
147 *osp = *perror_object;
148 errorexec_find(i_ctx_p, osp);
149 + /* If using SAFER, hand a name object to the error handler, rather than the executable
150 + * object/operator itself.
152 + if (i_ctx_p->LockFilePermissions) {
153 + code = obj_cvs(imemory, osp, buf + 2, 256, &rlen, (const byte **)&bufptr);
155 + const char *unknownstr = "--unknown--";
156 + rlen = strlen(unknownstr);
157 + memcpy(buf, unknownstr, rlen);
160 + buf[0] = buf[1] = buf[rlen + 2] = buf[rlen + 3] = '-';
163 + code = name_ref(imemory, buf, rlen, osp, 1);