From 950c602dc2dbbcbf5a856e85dba99bc8ac8420b9 Mon Sep 17 00:00:00 2001 From: Chris Liddell Date: Sat, 5 Mar 2016 14:56:03 -0800 Subject: [PATCH 1/1] Bug 694724: Have filenameforall and getenv honor SAFER --- Resource/Init/gs_init.ps | 1 + psi/zfile.c | 36 ++++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Resource/Init/gs_init.ps b/Resource/Init/gs_init.ps index c3f567d..abb9489 100644 --- a/Resource/Init/gs_init.ps +++ b/Resource/Init/gs_init.ps @@ -2019,6 +2019,7 @@ readonly def /LockFilePermissions //true >> setuserparams } + systemdict /getenv {pop //false} put if % setpagedevice has the side effect of clearing the page, but % we will just document that. Using setpagedevice keeps the device diff --git a/psi/zfile.c b/psi/zfile.c index 4011789..dd05919 100644 --- a/psi/zfile.c +++ b/psi/zfile.c @@ -371,22 +371,26 @@ file_continue(i_ctx_t *i_ctx_p) if (len < devlen) return_error(e_rangecheck); /* not even room for device len */ - memcpy((char *)pscratch->value.bytes, iodev->dname, devlen); - code = iodev->procs.enumerate_next(pfen, (char *)pscratch->value.bytes + devlen, - len - devlen); - if (code == ~(uint) 0) { /* all done */ - esp -= 5; /* pop proc, pfen, devlen, iodev , mark */ - return o_pop_estack; - } else if (code > len) /* overran string */ - return_error(e_rangecheck); - else { - push(1); - ref_assign(op, pscratch); - r_set_size(op, code + devlen); - push_op_estack(file_continue); /* come again */ - *++esp = pscratch[2]; /* proc */ - return o_push_estack; - } + + do { + memcpy((char *)pscratch->value.bytes, iodev->dname, devlen); + code = iodev->procs.enumerate_next(pfen, (char *)pscratch->value.bytes + devlen, + len - devlen); + if (code == ~(uint) 0) { /* all done */ + esp -= 5; /* pop proc, pfen, devlen, iodev , mark */ + return o_pop_estack; + } else if (code > len) /* overran string */ + return_error(gs_error_rangecheck); + else if (iodev != iodev_default(imemory) + || (check_file_permissions_reduced(i_ctx_p, (char *)pscratch->value.bytes, code + devlen, "PermitFileReading")) == 0) { + push(1); + ref_assign(op, pscratch); + r_set_size(op, code + devlen); + push_op_estack(file_continue); /* come again */ + *++esp = pscratch[2]; /* proc */ + return o_push_estack; + } + } while(1); } /* Cleanup procedure for enumerating files */ static int -- 2.7.4