GraphicsMagick: Make "operator" parameter checking more robust.

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.1769.1678579911.1409.graphicsmagick-commit@lists.sourceforge.net>
changeset 199faf0a0585 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=199faf0a0585
summary: Make "operator" parameter checking more robust.

diffstat:

 ChangeLog          |   4 ++
 magick/command.c   |  78 ++++++++++++++++++++++++++++++++++++++---------------
 www/Changelog.html |   3 ++
 3 files changed, 62 insertions(+), 23 deletions(-)

diffs (142 lines):

diff -r 80dc785ea112 -r 199faf0a0585 ChangeLog
--- a/ChangeLog	Sat Mar 11 15:08:43 2023 -0600
+++ b/ChangeLog	Sat Mar 11 18:11:41 2023 -0600
@@ -1,5 +1,9 @@
 2023-03-11  Bob Friesenhahn  <[email protected]>
 
+	* magick/command.c: Make "operator" parameter checking more
+	robust. Addresses SourceForge issue #690 "Segmentation Violations
+	in gm (magick/utility.c:3397)".
+
 	* coders/msl.c (ProcessMSLScript): Fix use of memory just freed.
 	Addresses SourceForge issue #689 "Heap UAF in gm
 	(magick/utility.c:3792)"
diff -r 80dc785ea112 -r 199faf0a0585 magick/command.c
--- a/magick/command.c	Sat Mar 11 15:08:43 2023 -0600
+++ b/magick/command.c	Sat Mar 11 18:11:41 2023 -0600
@@ -5595,6 +5595,11 @@
                   ThrowConvertException(OptionError,MissingArgument,
                     option);
               }
+            else
+              {
+                ThrowConvertException(OptionError,MissingArgument,
+                                      option);
+              }
             break;
           }
         if (LocaleCompare("ordered-dither",option+1) == 0)
@@ -10386,28 +10391,42 @@
           }
         if (LocaleCompare("operator",option+1) == 0)
           {
-            ChannelType
-              channel;
-
-            QuantumOperator
-              quantum_operator;
-
-            double
-              rvalue;
-
-            /* channel */
-            channel=StringToChannelType(argv[++i]);
-
-            /* operator id */
-            quantum_operator=StringToQuantumOperator(argv[++i]);
-
-            /* rvalue */
-            option=argv[++i];
-            rvalue=StringToDouble(option,MaxRGB);
-            (void) QuantumOperatorImage(*image,channel,quantum_operator,
-               rvalue,&(*image)->exception);
-
-            continue;
+            if (*option == '-')
+              {
+                ChannelType
+                  channel;
+
+                QuantumOperator
+                  quantum_operator;
+
+                double
+                  rvalue;
+
+                if ((argv[i+1] == NULL) || (argv[i+2] == NULL) || (argv[i+3] == NULL))
+                  {
+                    ThrowException(&(*image)->exception,OptionError,MissingArgument,option+1);
+                    break;
+                  }
+
+                /* channel */
+                channel=StringToChannelType(argv[++i]);
+
+                /* operator id */
+                quantum_operator=StringToQuantumOperator(argv[++i]);
+
+                /* rvalue */
+                option=argv[++i];
+                rvalue=StringToDouble(option,MaxRGB);
+                (void) QuantumOperatorImage(*image,channel,quantum_operator,
+                                            rvalue,&(*image)->exception);
+
+                continue;
+              }
+            else
+              {
+                ThrowException(&(*image)->exception,OptionError,MissingArgument,option+1);
+                break;
+              }
           }
         if (LocaleCompare("ordered-dither",option+1) == 0)
           {
@@ -13241,6 +13260,11 @@
                   ThrowMogrifyException(OptionError,MissingArgument,
                     option);
               }
+            else
+              {
+                ThrowMogrifyException(OptionError,MissingArgument,
+                    option);
+              }
             break;
           }
         if (LocaleCompare("ordered-dither",option+1) == 0)
@@ -14856,6 +14880,10 @@
           break;
         ThrowMontageException(OptionError,UnrecognizedOption,option)
       }
+      case 'o':
+      {
+        ThrowMontageException(OptionError,UnrecognizedOption,option)
+      }
       case 'p':
       {
         if (LocaleCompare("page",option+1) == 0)
@@ -15144,7 +15172,11 @@
               }
             break;
           }
-        ThrowMontageException(OptionError,UnrecognizedOption,option)
+        ThrowMontageException(OptionError,UnrecognizedOption,option);
+      }
+    case 'u':
+      {
+        ThrowMontageException(OptionError,UnrecognizedOption,option);
       }
       case 'v':
       {
diff -r 80dc785ea112 -r 199faf0a0585 www/Changelog.html
--- a/www/Changelog.html	Sat Mar 11 15:08:43 2023 -0600
+++ b/www/Changelog.html	Sat Mar 11 18:11:41 2023 -0600
@@ -40,6 +40,9 @@
 <p>2023-03-11  Bob Friesenhahn  &lt;<a class="reference external" href="mailto:bfriesen&#37;&#52;&#48;simple&#46;dallas&#46;tx&#46;us">bfriesen<span>&#64;</span>simple<span>&#46;</span>dallas<span>&#46;</span>tx<span>&#46;</span>us</a>&gt;</p>
 <blockquote>
 <ul class="simple">
+<li><p>magick/command.c: Make &quot;operator&quot; parameter checking more
+robust. Addresses SourceForge issue #690 &quot;Segmentation Violations
+in gm (magick/utility.c:3397)&quot;.</p></li>
 <li><p>coders/msl.c (ProcessMSLScript): Fix use of memory just freed.
 Addresses SourceForge issue #689 &quot;Heap UAF in gm
 (magick/utility.c:3792)&quot;</p></li>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.