summaryrefslogtreecommitdiffstats
path: root/meta/recipes-extended/ghostscript/ghostscript/CVE-2019-14817-0002.patch
blob: 6348fff2d13ae154c32412110f6778ed584a7999 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
From cd1b1cacadac2479e291efe611979bdc1b3bdb19 Mon Sep 17 00:00:00 2001
From: Ken Sharp <ken.sharp@artifex.com>
Date: Wed, 21 Aug 2019 10:10:51 +0100
Subject: [PATCH 2/2] PDF interpreter - review .forceput security

Bug #701450 "Safer Mode Bypass by .forceput Exposure in .pdfexectoken"

By abusing the error handler it was possible to get the PDFDEBUG portion
of .pdfexectoken, which uses .forceput left readable.

Add an executeonly appropriately to make sure that clause isn't readable
no mstter what.

Review all the uses of .forceput searching for similar cases, add
executeonly as required to secure those. All cases in the PostScript
support files seem to be covered already.

CVE: CVE-2019-14817
Upstream-Status: Backport [git://git.ghostscript.com/ghostpdl.git]

Signed-off-by: Stefan Ghinea <stefan.ghinea@windriver.com>
---
 Resource/Init/pdf_base.ps |  2 +-
 Resource/Init/pdf_draw.ps | 14 +++++++-------
 Resource/Init/pdf_font.ps | 29 ++++++++++++++++-------------
 Resource/Init/pdf_main.ps |  6 +++---
 Resource/Init/pdf_ops.ps  | 11 ++++++-----
 5 files changed, 33 insertions(+), 29 deletions(-)

diff --git a/Resource/Init/pdf_base.ps b/Resource/Init/pdf_base.ps
index 1a218f4..cffde5c 100644
--- a/Resource/Init/pdf_base.ps
+++ b/Resource/Init/pdf_base.ps
@@ -157,7 +157,7 @@ currentdict /num-chars-dict .undef
     {
       dup ==only () = flush
     } ifelse % PDFSTEP
-  } if % PDFDEBUG
+  } executeonly if % PDFDEBUG
   2 copy .knownget {
     exch pop exch pop exch pop exec
   } {
diff --git a/Resource/Init/pdf_draw.ps b/Resource/Init/pdf_draw.ps
index e18a7c2..0a3924c 100644
--- a/Resource/Init/pdf_draw.ps
+++ b/Resource/Init/pdf_draw.ps
@@ -501,8 +501,8 @@ end
       (        Output may be incorrect.\n) pdfformaterror
       //pdfdict /.gs_warning_issued //true .forceput
       PDFSTOPONERROR { /gs /undefined signalerror } if
-    } if
-  }
+    } executeonly if
+  } executeonly
   ifelse
 } bind executeonly def
 
@@ -1142,7 +1142,7 @@ currentdict end readonly def
           .setglobal
           pdfformaterror
         } executeonly ifelse
-      }
+      } executeonly
       {
         currentglobal //pdfdict gcheck .setglobal
         //pdfdict /.Qqwarning_issued //true .forceput
@@ -1150,8 +1150,8 @@ currentdict end readonly def
         pdfformaterror
       } executeonly ifelse
       end
-    } ifelse
-  } loop
+    } executeonly ifelse
+  } executeonly loop
   {
     (\n   **** Error: File has unbalanced q/Q operators \(too many q's\)\n               Output may be incorrect.\n)
     //pdfdict /.Qqwarning_issued .knownget
@@ -1165,14 +1165,14 @@ currentdict end readonly def
         .setglobal
         pdfformaterror
       } executeonly ifelse
-    }
+    } executeonly
     {
       currentglobal //pdfdict gcheck .setglobal
       //pdfdict /.Qqwarning_issued //true .forceput
       .setglobal
       pdfformaterror
     } executeonly ifelse
-  } if
+  } executeonly if
   pop
 
   % restore pdfemptycount
diff --git a/Resource/Init/pdf_font.ps b/Resource/Init/pdf_font.ps
index 2df3303..6a6a5fe 100644
--- a/Resource/Init/pdf_font.ps
+++ b/Resource/Init/pdf_font.ps
@@ -638,7 +638,7 @@ currentdict end readonly def
                   currentglobal 2 index dup gcheck setglobal
                   /FontInfo 5 dict dup 5 1 roll .forceput
                   setglobal
-                } if
+                } executeonly if
                 dup /GlyphNames2Unicode .knownget not {
                   //true                        % No existing G2U, make one
                 } {
@@ -668,10 +668,12 @@ currentdict end readonly def
                 pop                                     % font-res font-dict encoding|null font-info
                 pop                                     % font-res font-dict encoding|null
                 //false                                 % We built a GlyphNames2Unicode table, don't need to process further
-              }{
+              } executeonly
+              {
                 //true                                  % name is not Identity-V or H, fail by falling through
               }ifelse
-          } {
+          } executeonly
+          {
             //true
           } ifelse                                      % not a name, try as a dictionary (as specified)
 
@@ -759,9 +761,9 @@ currentdict end readonly def
           PDFDEBUG {
             (.processToUnicode end) =
           } if
-        } if
-      } if
-    } stopped
+        } executeonly if
+      } executeonly if
+    } executeonly stopped
     {
       .dstackdepth 1 countdictstack 1 sub
       {pop end} for
@@ -1291,19 +1293,20 @@ currentdict /eexec_pdf_param_dict .undef
                 //pdfdict /.Qqwarning_issued //true .forceput
               } executeonly if
               Q
-            } repeat
+            } executeonly repeat
             Q
-          } PDFfile fileposition 2 .execn % Keep pdfcount valid.
+          } executeonly PDFfile fileposition 2 .execn % Keep pdfcount valid.
           PDFfile exch setfileposition
-        } ifelse
-      } {
+        } executeonly ifelse
+      } executeonly
+      {
         % PDF Type 3 fonts don't use .notdef
         % d1 implementation adjusts the width as needed
         0 0 0 0 0 0
         pdfopdict /d1 get exec
       } ifelse
       end end
-    } bdef
+    } executeonly bdef
     dup currentdict Encoding .processToUnicode
     currentdict end .completefont exch pop
 } bind executeonly odef
@@ -2103,9 +2106,9 @@ currentdict /CMap_read_dict undef
           (Will continue, but content may be missing.) = flush
         } ifelse
       } if
-    } if
+    } executeonly if
     /findresource cvx /undefined signalerror
-  } loop
+  } executeonly loop
 } bind executeonly odef
 
 /buildCIDType0 {	% <CIDFontType0-font-resource> buildCIDType0 <font>
diff --git a/Resource/Init/pdf_main.ps b/Resource/Init/pdf_main.ps
index 5305ea6..a59e63c 100644
--- a/Resource/Init/pdf_main.ps
+++ b/Resource/Init/pdf_main.ps
@@ -2749,15 +2749,15 @@ currentdict /PDF2PS_matrix_key undef
           .setglobal
           pdfformaterror
         } executeonly ifelse
-      }
+      } executeonly
       {
         currentglobal //pdfdict gcheck .setglobal
         //pdfdict /.Qqwarning_issued //true .forceput
         .setglobal
         pdfformaterror
       } executeonly ifelse
-    } if
-  } if
+    } executeonly if
+  } executeonly if
   pop
   count PDFexecstackcount sub { pop } repeat
   (after exec) VMDEBUG
diff --git a/Resource/Init/pdf_ops.ps b/Resource/Init/pdf_ops.ps
index 285e582..6c1f100 100644
--- a/Resource/Init/pdf_ops.ps
+++ b/Resource/Init/pdf_ops.ps
@@ -186,14 +186,14 @@ currentdict /gput_always_allow .undef
         .setglobal
         pdfformaterror
       } executeonly ifelse
-    }
+    } executeonly
     {
       currentglobal //pdfdict gcheck .setglobal
       //pdfdict /.Qqwarning_issued //true .forceput
       .setglobal
       pdfformaterror
     } executeonly ifelse
-  } if
+  } executeonly if
 } bind executeonly odef
 
 % Save PDF gstate
@@ -440,11 +440,12 @@ currentdict /gput_always_allow .undef
   dup type /booleantype eq {
     .currentSMask type /dicttype eq {
       .currentSMask /Processed 2 index .forceput
+    } executeonly
+    {
+      .setSMask
+    }ifelse
   } executeonly
   {
-      .setSMask
-  }ifelse
-  }{
   .setSMask
   }ifelse
 
-- 
2.20.1