summaryrefslogtreecommitdiff
path: root/psi
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2023-03-09 19:46:42 +0000
committerRobin Watts <Robin.Watts@artifex.com>2023-03-09 19:46:42 +0000
commit7456fbd3b0581c278279b5f138adaf0f464449c2 (patch)
tree0a0a8341f634b1b73a7c04a8749aae2630c50bbf /psi
parent6b68da571b22ff6cd68a145cb0470365c684c311 (diff)
downloadghostpdl-7456fbd3b0581c278279b5f138adaf0f464449c2.tar.gz
Bug 706465: Avoid zero-page access in swift interpreter exit.
If "-Z:" debugging is enabled, and the interpreter exits without doing anything, we can attempt to access a memory structure without it being there. Guard against this. Thanks to Youngseok Choi for the report!
Diffstat (limited to 'psi')
-rw-r--r--psi/imain.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/psi/imain.c b/psi/imain.c
index 82de73434..fdf9d47f0 100644
--- a/psi/imain.c
+++ b/psi/imain.c
@@ -530,7 +530,7 @@ gs_main_init2(gs_main_instance * minst)
if (code >= 0) {
if (gs_debug_c(':'))
- print_resource_usage(minst, &gs_imemory, "Start");
+ print_resource_usage(minst, i_ctx_p ? &gs_imemory : NULL, "Start");
gp_readline_init(&minst->readline_data, minst->heap); /* lgtm [cpp/useless-expression] */
}
@@ -1390,7 +1390,7 @@ gs_main_finit(gs_main_instance * minst, int exit_status, int env_code)
gs_free_object(minst->heap, minst->saved_pages_initial_arg, "gs_main_finit");
i_ctx_p = minst->i_ctx_p; /* get current interp context */
if (gs_debug_c(':')) {
- print_resource_usage(minst, &gs_imemory, "Final");
+ print_resource_usage(minst, i_ctx_p ? &gs_imemory : NULL, "Final");
dmprintf1(minst->heap, "%% Exiting instance "PRI_INTPTR"\n", (intptr_t)minst);
}
/* Do the equivalent of a restore "past the bottom". */
@@ -1470,22 +1470,25 @@ print_resource_usage(const gs_main_instance * minst, gs_dual_memory_t * dmem,
ulong used = 0; /* this we accumulate for the PS memories */
long utime[2];
int i;
- gs_memory_status_t status;
+ gs_memory_status_t status = { 0 };
gp_get_realtime(utime);
- for (i = 0; i < countof(dmem->spaces_indexed); ++i) {
- gs_ref_memory_t *mem = dmem->spaces_indexed[i];
+ if (dmem)
+ {
+ for (i = 0; i < countof(dmem->spaces_indexed); ++i) {
+ gs_ref_memory_t *mem = dmem->spaces_indexed[i];
- if (mem != 0 && (i == 0 || mem != dmem->spaces_indexed[i - 1])) {
- gs_ref_memory_t *mem_stable =
- (gs_ref_memory_t *)gs_memory_stable((gs_memory_t *)mem);
+ if (mem != 0 && (i == 0 || mem != dmem->spaces_indexed[i - 1])) {
+ gs_ref_memory_t *mem_stable =
+ (gs_ref_memory_t *)gs_memory_stable((gs_memory_t *)mem);
- gs_memory_status((gs_memory_t *)mem, &status);
- used += status.used;
- if (mem_stable != mem) {
- gs_memory_status((gs_memory_t *)mem_stable, &status);
+ gs_memory_status((gs_memory_t *)mem, &status);
used += status.used;
+ if (mem_stable != mem) {
+ gs_memory_status((gs_memory_t *)mem_stable, &status);
+ used += status.used;
+ }
}
}
}