1 From 34a8c5aa987d4db5234172a62218b168371606b1 Mon Sep 17 00:00:00 2001
2 From: Chris Liddell <chris.liddell@artifex.com>
3 Date: Tue, 2 Oct 2018 16:02:58 +0100
4 Subject: [PATCH 4/5] For hidden operators, pass a name object to error
7 In normal operation, Postscript error handlers are passed the object which
8 triggered the error: this is invariably an operator object.
10 The issue arises when an error is triggered by an operator which is for internal
11 use only, and that operator is then passed to the error handler, meaning it
12 becomes visible to the error handler code.
14 By converting to a name object, the error message is still valid, but we no
15 longer expose internal use only operators.
17 The change in gs_dps1.ps is related to the above: previously an error in
18 scheck would throw an error against .gcheck, but as .gcheck is now a hidden
19 operator, it resulted in a name object being passed to the error handler. As
20 scheck is a 'real' operator, it's better to use the real operator, rather than
21 the name of an internal, hidden one.
24 Upstream-Status: Backport [git://git.ghostscript.com/ghostpdl.git]
25 Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
27 Resource/Init/gs_dps1.ps | 2 +-
28 psi/interp.c | 33 ++++++++++++++++++++++++---------
29 2 files changed, 25 insertions(+), 10 deletions(-)
31 diff --git a/Resource/Init/gs_dps1.ps b/Resource/Init/gs_dps1.ps
32 index 1182f53..ec5db61 100644
33 --- a/Resource/Init/gs_dps1.ps
34 +++ b/Resource/Init/gs_dps1.ps
35 @@ -21,7 +21,7 @@ level2dict begin
36 % ------ Virtual memory ------ %
38 /currentshared /.currentglobal load def
39 -/scheck /.gcheck load def
40 +/scheck {.gcheck} bind odef
41 %****** FOLLOWING IS WRONG ******
42 /shareddict currentdict /globaldict .knownget not { 20 dict } if def
44 diff --git a/psi/interp.c b/psi/interp.c
45 index cd894f9..b70769d 100644
48 @@ -678,6 +678,8 @@ again:
50 /* Push the error object on the operand stack if appropriate. */
51 if (!GS_ERROR_IS_INTERRUPT(code)) {
52 + byte buf[260], *bufptr;
54 /* Replace the error object if within an oparray or .errorexec. */
57 @@ -686,23 +688,36 @@ again:
59 *osp = *perror_object;
60 errorexec_find(i_ctx_p, osp);
61 - /* If using SAFER, hand a name object to the error handler, rather than the executable
62 - * object/operator itself.
64 - if (i_ctx_p->LockFilePermissions) {
66 + if (!r_has_type(osp, t_string) && !r_has_type(osp, t_name)) {
67 code = obj_cvs(imemory, osp, buf + 2, 256, &rlen, (const byte **)&bufptr);
69 const char *unknownstr = "--unknown--";
70 rlen = strlen(unknownstr);
71 memcpy(buf, unknownstr, rlen);
75 - buf[0] = buf[1] = buf[rlen + 2] = buf[rlen + 3] = '-';
78 + bufptr[rlen] = '\0';
79 + /* Only pass a name object if the operator doesn't exist in systemdict
80 + * i.e. it's an internal operator we have hidden
82 + code = dict_find_string(systemdict, (const char *)bufptr, &tobj);
84 + buf[0] = buf[1] = buf[rlen + 2] = buf[rlen + 3] = '-';
93 + code = name_ref(imemory, buf, rlen, osp, 1);
97 - code = name_ref(imemory, buf, rlen, osp, 1);