diff options
author | Chris Liddell <chris.liddell@artifex.com> | 2017-07-06 14:54:02 +0100 |
---|---|---|
committer | Chris Liddell <chris.liddell@artifex.com> | 2017-07-25 09:07:07 +0100 |
commit | 671fd59eb657743aa86fbc1895cb15872a317caa (patch) | |
tree | 6dbe92f8487df993d959cc812f9cf6b38aa13fe1 | |
parent | 18a2365b69cc43ed4dbe2bfd44f739622623821c (diff) |
Bug 698158: prevent trying to reloc a freed object
In the token reader, we pass the scanner state structure around as a
t_struct ref on the Postscript operand stack.
But we explicitly free the scanner state when we're done, which leaves a
dangling reference on the operand stack and, unless that reference gets
overwritten before the next garbager run, we can end up with the garbager
trying to deal with an already freed object - that can cause a crash, or
memory corruption.
-rw-r--r-- | psi/ztoken.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/psi/ztoken.c b/psi/ztoken.c index 4dba7c5bd..af1ceeb4f 100644 --- a/psi/ztoken.c +++ b/psi/ztoken.c | |||
@@ -107,6 +107,12 @@ token_continue(i_ctx_t *i_ctx_p, scanner_state * pstate, bool save) | |||
107 | int code; | 107 | int code; |
108 | ref token; | 108 | ref token; |
109 | 109 | ||
110 | /* Since we might free pstate below, and we're dealing with | ||
111 | * gc memory referenced by the stack, we need to explicitly | ||
112 | * remove the reference to pstate from the stack, otherwise | ||
113 | * the garbager will fall over | ||
114 | */ | ||
115 | make_null(osp); | ||
110 | /* Note that gs_scan_token may change osp! */ | 116 | /* Note that gs_scan_token may change osp! */ |
111 | pop(1); /* remove the file or scanner state */ | 117 | pop(1); /* remove the file or scanner state */ |
112 | again: | 118 | again: |
@@ -183,8 +189,14 @@ ztokenexec_continue(i_ctx_t *i_ctx_p) | |||
183 | static int | 189 | static int |
184 | tokenexec_continue(i_ctx_t *i_ctx_p, scanner_state * pstate, bool save) | 190 | tokenexec_continue(i_ctx_t *i_ctx_p, scanner_state * pstate, bool save) |
185 | { | 191 | { |
186 | os_ptr op; | 192 | os_ptr op = osp; |
187 | int code; | 193 | int code; |
194 | /* Since we might free pstate below, and we're dealing with | ||
195 | * gc memory referenced by the stack, we need to explicitly | ||
196 | * remove the reference to pstate from the stack, otherwise | ||
197 | * the garbager will fall over | ||
198 | */ | ||
199 | make_null(osp); | ||
188 | /* Note that gs_scan_token may change osp! */ | 200 | /* Note that gs_scan_token may change osp! */ |
189 | pop(1); | 201 | pop(1); |
190 | again: | 202 | again: |