]> code.ossystems Code Review - openembedded-core.git/blob
ccd40216c03257460ee144191b6b0c0a871095ce
[openembedded-core.git] /
1 From f4f50ceea8e8852b8c3ac73f5807d8b54b735c3e Mon Sep 17 00:00:00 2001
2 From: Chris Liddell <chris.liddell@artifex.com>
3 Date: Tue, 21 Aug 2018 20:17:05 +0100
4 Subject: [PATCH 5/5] Bug 699657: properly apply file permissions to .tempfile
5
6 CVE: CVE-2018-15908
7 Upstream-Status: Backport [git://git.ghostscript.com/ghostpdl.git]
8
9 Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
10 ---
11  psi/zfile.c | 20 ++++++++++++++++++--
12  1 file changed, 18 insertions(+), 2 deletions(-)
13
14 diff --git a/psi/zfile.c b/psi/zfile.c
15 index a0acd5a..19996b0 100644
16 --- a/psi/zfile.c
17 +++ b/psi/zfile.c
18 @@ -134,7 +134,7 @@ check_file_permissions_reduced(i_ctx_t *i_ctx_p, const char *fname, int len,
19      /* we're protecting arbitrary file system accesses, not Postscript device accesses.
20       * Although, note that %pipe% is explicitly checked for and disallowed elsewhere
21       */
22 -    if (iodev != iodev_default(imemory)) {
23 +    if (iodev && iodev != iodev_default(imemory)) {
24          return 0;
25      }
26  
27 @@ -734,7 +734,23 @@ ztempfile(i_ctx_t *i_ctx_p)
28      }
29  
30      if (gp_file_name_is_absolute(pstr, strlen(pstr))) {
31 -        if (check_file_permissions(i_ctx_p, pstr, strlen(pstr),
32 +        int plen = strlen(pstr);
33 +        const char *sep = gp_file_name_separator();
34 +#ifdef DEBUG
35 +        int seplen = strlen(sep);
36 +        if (seplen != 1)
37 +            return_error(gs_error_Fatal);
38 +#endif
39 +        /* strip off the file name prefix, leave just the directory name
40 +         * so we can check if we are allowed to write to it
41 +         */
42 +        for ( ; plen >=0; plen--) {
43 +            if (pstr[plen] == sep[0])
44 +                break;
45 +        }
46 +        memcpy(fname, pstr, plen);
47 +        fname[plen] = '\0';
48 +        if (check_file_permissions(i_ctx_p, fname, strlen(fname),
49                                     NULL, "PermitFileWriting") < 0) {
50              code = gs_note_error(gs_error_invalidfileaccess);
51              goto done;
52 -- 
53 2.8.1
54