summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2023-02-09 17:18:54 +0000
committerRobin Watts <Robin.Watts@artifex.com>2023-02-09 17:40:48 +0000
commit1897bc5acff438f5628712139f6ee5f47d9a6e54 (patch)
treefcc1ee71437e81227bbd9973eeb1a16459afc0fd /base
parent95db9c543abdeb391d852aad7f0c5c419f808069 (diff)
downloadghostpdl-1897bc5acff438f5628712139f6ee5f47d9a6e54.tar.gz
Bug 706380: Fix argument quote handling following hash.
When parsing arguments, we have special handling for quote marks. We interpret them as literal quotes, unless they are either at the start of an argument, or immediately following an '=' sign, so that: ThisIsAFileWithA"InTheName.pdf and -sOutputFile="File 1.pdf" both work as you'd expect. Unfortunately, in the dim, dark, uncharted past that is Ghostscript history, someone decided that it'd be a spiffy idea for people to be able to use the hash character (that one that I can't type in here because git will think it's a comment character) as a replacement for '='. The special handling to keep track if we had just seen an equals sign was not coping with having just seen a hash mark. Fixed here. We also take the opportunity to fix a memory leak in the handling of @files - ensuring we free the allocated block for the stream when we return from reading from it.
Diffstat (limited to 'base')
-rw-r--r--base/gsargs.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/base/gsargs.c b/base/gsargs.c
index d2402563d..a55a9ca9f 100644
--- a/base/gsargs.c
+++ b/base/gsargs.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2022 Artifex Software, Inc.
+/* Copyright (C) 2001-2023 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
@@ -250,8 +250,11 @@ arg_next(arg_list * pal, const char **argstr, const gs_memory_t *errmem)
} while (c > 0 && c < 256 && isspace(c));
if (c == EOF) {
/* EOF before any argument characters. */
- if (pas->is_file)
+ if (pas->is_file) {
sclose(pas->u.strm);
+ gs_free_object(pas->u.strm->memory, pas->u.strm, "arg stream");
+ pas->u.strm = NULL;
+ }
else if (pas->u.s.memory)
gs_free_object(pas->u.s.memory, pas->u.s.chars,
"arg_next");
@@ -380,7 +383,7 @@ arg_next(arg_list * pal, const char **argstr, const gs_memory_t *errmem)
else
i += codepoint_to_utf8(&cstr[i], c);
eol = is_eol(c);
- prev_c_was_equals = (c == '=');
+ prev_c_was_equals = (c == '=') || (c == '#');
c = get_codepoint(pal, pas);
}
cstr[i] = 0;