diff options
author | Chris Liddell <chris.liddell@artifex.com> | 2019-09-23 17:56:34 +0100 |
---|---|---|
committer | Chris Liddell <chris.liddell@artifex.com> | 2019-09-24 08:31:53 +0100 |
commit | f874c5b9d2d5a3798dc00e53149c4a470ce5da01 (patch) | |
tree | 5e365923b31f171fb4ca07c56287a35078dc6f35 /base | |
parent | a1c253838b0e1ccbadc5c0bdb6e3bde59b3b00a1 (diff) | |
download | ghostpdl-f874c5b9d2d5a3798dc00e53149c4a470ce5da01.tar.gz |
Fix tiffsep(1) interaction with file permissions lists
The previous solution didn't quite work, when using formatted strings for
output file names (i.e. output-%d.tif).
This adds a dedicated gs_remove_outputfile_control_path() to mirror
gs_add_outputfile_control_path() and uses those for the dynamic adding and
removing of separation output file names.
Diffstat (limited to 'base')
-rw-r--r-- | base/gslibctx.c | 40 | ||||
-rw-r--r-- | base/gslibctx.h | 3 |
2 files changed, 43 insertions, 0 deletions
diff --git a/base/gslibctx.c b/base/gslibctx.c index 5b00d64e0..64e214d69 100644 --- a/base/gslibctx.c +++ b/base/gslibctx.c @@ -683,6 +683,46 @@ gs_add_outputfile_control_path(gs_memory_t *mem, const char *fname) } int +gs_remove_outputfile_control_path(gs_memory_t *mem, const char *fname) +{ + char *fp, f[gp_file_name_sizeof]; + const int pipe = 124; /* ASCII code for '|' */ + const int len = strlen(fname); + + /* Be sure the string copy will fit */ + if (len >= gp_file_name_sizeof) + return gs_error_rangecheck; + strcpy(f, fname); + fp = f; + /* Try to rewrite any %d (or similar) in the string */ + if (!rewrite_percent_specifiers(f)) { + /* No %d found, so check for pipes */ + int i; + fp = f; + for (i = 0; i < len; i++) { + if (f[i] == pipe) { + int code; + + fp = &f[i + 1]; + /* Because we potentially have to check file permissions at two levels + for the output file (gx_device_open_output_file and the low level + fopen API, if we're using a pipe, we have to add both the full string, + (including the '|', and just the command to which we pipe - since at + the pipe_fopen(), the leading '|' has been stripped. + */ + code = gs_remove_control_path(mem, gs_permit_file_writing, f); + if (code < 0) + return code; + break; + } + if (!IS_WHITESPACE(f[i])) + break; + } + } + return gs_remove_control_path(mem, gs_permit_file_writing, fp); +} + +int gs_add_explicit_control_path(gs_memory_t *mem, const char *arg, gs_path_control_t control) { char *p2, *p1 = (char *)arg; diff --git a/base/gslibctx.h b/base/gslibctx.h index 142501449..79bc9da8d 100644 --- a/base/gslibctx.h +++ b/base/gslibctx.h @@ -243,6 +243,9 @@ int gs_add_outputfile_control_path(gs_memory_t *mem, const char *fname); int +gs_remove_outputfile_control_path(gs_memory_t *mem, const char *fname); + +int gs_add_explicit_control_path(gs_memory_t *mem, const char *arg, gs_path_control_t control); int |