Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates-src > by-pkgid > 09236aad26217818763c178cc3a83744 > files > 12

ghostscript-9.24-1.5.mga6.src.rpm

From a8c7899267121cb92503fe0f7e7f6ae433c386b1 Mon Sep 17 00:00:00 2001
From: Robin Watts <robin.watts@artifex.com>
Date: Wed, 5 Sep 2018 15:59:43 +0100
Subject: [PATCH] Bug 699711: Review arg_next to ensure that NULL arg returns
 are coped with.

We can only return NULL from arg_next if the return code == 0. We
therefore have to ensure that all call sites check for either of
those conditions.
---
 base/gsargs.c   | 17 +++++++++++------
 psi/imainarg.c  |  4 ++--
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/base/gsargs.c b/base/gsargs.c
index 028529f..894d38c 100644
--- a/base/gsargs.c
+++ b/base/gsargs.c
@@ -244,12 +244,17 @@ arg_next(arg_list * pal, const char **argstr, const gs_memory_t *errmem)
                                    "arg_next");
                 /* If depth is 0, then we are reading from the simple
                  * argument list and we just hit an "empty" argument
-                 * (such as -o ""). Just ignore it and look for the next
-                 * one. If depth > 0, then we're reading from a response
-                 * file, and we can't have empty arguments - so we've
-                 * hit the end of the response file. Pop up one level. */
-                if (pal->depth > 0)
-                    pal->depth--;
+                 * (such as -o ""). Return this. */
+                if (pal->depth == 0)
+                {
+                    *argstr = pal->cstr;
+                    pal->cstr[0] = 0;
+                    break;
+                }
+                /* If depth > 0, then we're reading from a response
+                 * file, and we've hit the end of the response file.
+                 * Pop up one level and continue. */
+                pal->depth--;
                 continue; /* Next argument */
             }
     #define is_eol(c) (c == '\r' || c == '\n')
diff --git a/psi/imainarg.c b/psi/imainarg.c
index 9dbb70a..fb16f4b 100644
--- a/psi/imainarg.c
+++ b/psi/imainarg.c
@@ -429,7 +429,7 @@ run_stdin:
 
                 if (code < 0)
                     return gs_error_Fatal;
-                if (psarg == 0) {
+                if (psarg == NULL) {
                     outprintf(minst->heap, "Usage: gs ... -%c file.ps arg1 ... argn\n", sw);
                     arg_finit(pal);
                     return gs_error_Fatal;
@@ -504,7 +504,7 @@ run_stdin:
                 }
                 if (code < 0)
                     return gs_error_Fatal;
-                if (arg != 0) {
+                if (arg != NULL) {
                     char *p = arg_copy(arg, minst->heap);
                     if (p == NULL)
                         return gs_error_Fatal;
-- 
2.9.1