From 5b5968c306b3e35cdeec83bb15026fd74a7334de Mon Sep 17 00:00:00 2001
From: Ken Sharp <Ken.Sharp@artifex.com>
Date: Sat, 12 Apr 2025 10:24:43 +0100
Subject: [PATCH] Argument sanitisation - handle '#' as per '='

Bug 708446

CVE: CVE-2025-48708

Upstream-Status: Backport [https://cgit.ghostscript.com/cgi-bin/cgit.cgi/ghostpdl.git/commit/?id=5b5968c306b3e35cdeec83bb15026fd74a7334de]

Signed-off-by: Archana Polampalli <archana.polampalli@windriver.com>
---
 base/gslibctx.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/base/gslibctx.c b/base/gslibctx.c
index 2cf5c9dda..40ff984f9 100644
--- a/base/gslibctx.c
+++ b/base/gslibctx.c
@@ -1225,9 +1225,9 @@ gs_lib_ctx_stash_sanitized_arg(gs_lib_ctx_t *ctx, const char *arg)
         case '-': /* Need to check for permitted file lists */
             /* By default, we want to keep the key, but lose the value */
             p = arg+2;
-            while (*p && *p != '=')
+            while (*p && *p != '=' && *p != '#')
                 p++;
-            if (*p == '=')
+            if (*p == '=' || *p == '#')
                 p++;
             if (*p == 0)
                 break; /* No value to elide */
@@ -1269,9 +1269,9 @@ gs_lib_ctx_stash_sanitized_arg(gs_lib_ctx_t *ctx, const char *arg)
         case 'S':
             /* By default, we want to keep the key, but lose the value */
             p = arg+2;
-            while (*p && *p != '=')
+            while (*p && *p != '=' && *p != '#')
                 p++;
-            if (*p == '=')
+            if (*p == '=' || *p == '#')
                 p++;
             if (*p == 0)
                 break; /* No value to elide */
--
2.40.0
