GraphicsMagick: Coverity: Fix recently-added sizeof() regressions.

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.30100.1670691830.1567.graphicsmagick-commit@lists.sourceforge.net>
changeset 8317983b3b31 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=8317983b3b31
summary: Coverity: Fix recently-added sizeof() regressions.

diffstat:

 ChangeLog          |  29 +++++++++++++++++++++++++++++
 Makefile.am        |  27 +++++++++++++++++----------
 Makefile.in        |  29 ++++++++++++++++++-----------
 coders/jpeg.c      |   8 +++++---
 coders/meta.c      |  16 ++++++++++++----
 magick/widget.c    |  18 +++++++++---------
 www/Changelog.html |  25 +++++++++++++++++++++++++
 7 files changed, 115 insertions(+), 37 deletions(-)

diffs (365 lines):

diff -r 6233da622ab9 -r 8317983b3b31 ChangeLog
--- a/ChangeLog	Sat Dec 10 09:18:12 2022 -0600
+++ b/ChangeLog	Sat Dec 10 11:03:37 2022 -0600
@@ -1,5 +1,34 @@
 2022-12-10  Bob Friesenhahn  <[email protected]>
 
+	* coders/meta.c (parse8BIM): Fix Coverity 382245 "Incorrect
+	expression (SIZEOF_MISMATCH)".
+	(parse8BIMW): Fix Coverity 382250 "Incorrect expression
+	(SIZEOF_MISMATCH)".
+
+	* magick/widget.c (MagickXNoticeWidget): Fix Coverity 382254
+	"Incorrect expression (SIZEOF_MISMATCH)."
+	(MagickXFontBrowserWidget): Fix Coverity 382253 "Incorrect
+	expression (SIZEOF_MISMATCH)".
+	(MagickXFileBrowserWidget): Fix Coverity 382252 "Incorrect
+	expression (SIZEOF_MISMATCH)".
+	(MagickXPreferencesWidget): Fix Coverity 382251 "Incorrect
+	expression (SIZEOF_MISMATCH)".
+	(MagickXConfirmWidget): Fix Coverity 382249 "Incorrect expression
+	(SIZEOF_MISMATCH)".
+	(MagickXListBrowserWidget): Fix Coverity 382248 "Incorrect
+	expression (SIZEOF_MISMATCH)".
+	(MagickXDialogWidget): Fix Coverity 382247 "Incorrect expression
+	(SIZEOF_MISMATCH)".
+	(MagickXColorBrowserWidget): Fix Coverity 382246
+	"(SIZEOF_MISMATCH)".
+
+	* coders/jpeg.c (WriteICCProfile): Fix Coverity 382255 "Incorrect
+	expression (SIZEOF_MISMATCH)".
+
+	* Makefile.am (clean-local): Added a clean-local target to remove
+	Coverity subdirectory ('cov-int').  Building with 'coverity'
+	target leaves Coverity subdirectory in place for inspection.
+
 	* NEWS.txt: Updated the news.
 
 2022-12-04  Bob Friesenhahn  <[email protected]>
diff -r 6233da622ab9 -r 8317983b3b31 Makefile.am
--- a/Makefile.am	Sat Dec 10 09:18:12 2022 -0600
+++ b/Makefile.am	Sat Dec 10 11:03:37 2022 -0600
@@ -25,6 +25,16 @@
 MODULECOMMONFLAGS = -no-undefined -export-symbols-regex ".*" -shared -module -avoid-version
 MODULECOMMONCPPFLAGS = $(AM_CPPFLAGS)
 
+# Coverity parameters
+# FIXME: Could use info from /etc/os-release, or output from
+# lsb_release.
+# New URL is https://scan.coverity.com/projects/graphicsmagick?tab=overview
[email protected]
+COVERITY_TARBALL=GraphicsMagick.xz
+COVERITY_VERSION=snapshot-@PACKAGE_CHANGE_DATE@
+COVERITY_DESCRIPTION='Ubuntu Q@QuantumDepth@'
+COVERITY_COV_INT='cov-int'
+
 # Options to pass when running configure in the distcheck target.
 #
 # We want to preserve user-provided option variables so the same
@@ -273,6 +283,10 @@
 	  ) \
 	)
 
+# Special cleaning rules
+clean-local:
+	$(RM) -rf $(COVERITY_COV_INT)
+
 #
 # Additional install rules
 #
@@ -424,17 +438,11 @@
 
 endif # HasGRAPHICSMAGICK_SNAPSHOT_COPY
 
-# FIXME: Could use info from /etc/os-release, or output from
-# lsb_release.
[email protected]
-COVERITY_TARBALL=GraphicsMagick.xz
-COVERITY_VERSION=snapshot-@PACKAGE_CHANGE_DATE@
-COVERITY_DESCRIPTION='Ubuntu Q@QuantumDepth@'
-COVERITY_COV_INT='cov-int'
-# New URL is https://scan.coverity.com/projects/graphicsmagick?tab=overview
+# Build under Coverity
 coverity:
 	$(MAKE) clean
-	cov-build --dir cov-int $(MAKE)
+	$(RM) -rf $(COVERITY_COV_INT)
+	cov-build --dir $(COVERITY_COV_INT) $(MAKE)
 	tar caf $(COVERITY_TARBALL) cov-int
 	curl --limit-rate 34K \
 	--form token=`cat $$HOME/.coverity_key_gm` \
@@ -444,7 +452,6 @@
 	--form description=$(COVERITY_DESCRIPTION) \
 	https://scan.coverity.com/builds?project=GraphicsMagick
 	$(RM) $(COVERITY_TARBALL)
-	$(RM) -rf $(COVERITY_COV_INT)
 
 # Rules for a profiled build (according to Paolo Bonzini <[email protected]>)
 #profile:
diff -r 6233da622ab9 -r 8317983b3b31 Makefile.in
--- a/Makefile.in	Sat Dec 10 09:18:12 2022 -0600
+++ b/Makefile.in	Sat Dec 10 11:03:37 2022 -0600
@@ -2741,6 +2741,16 @@
 MODULECOMMONFLAGS = -no-undefined -export-symbols-regex ".*" -shared -module -avoid-version
 MODULECOMMONCPPFLAGS = $(AM_CPPFLAGS)
 
+# Coverity parameters
+# FIXME: Could use info from /etc/os-release, or output from
+# lsb_release.
+# New URL is https://scan.coverity.com/projects/graphicsmagick?tab=overview
+COVERITY_EMAIL = [email protected]
+COVERITY_TARBALL = GraphicsMagick.xz
+COVERITY_VERSION = snapshot-@PACKAGE_CHANGE_DATE@
+COVERITY_DESCRIPTION = 'Ubuntu Q@QuantumDepth@'
+COVERITY_COV_INT = 'cov-int'
+
 # Options to pass when running configure in the distcheck target.
 #
 # We want to preserve user-provided option variables so the same
@@ -4925,14 +4935,6 @@
 # Use a hard-coded mechanism and destination path to copy snapshot files
 @HasGRAPHICSMAGICK_SNAPSHOT_COPY_FALSE@SNAPSHOT_DIRECTORY = /ftp/pub/GraphicsMagick/snapshots
 
-# FIXME: Could use info from /etc/os-release, or output from
-# lsb_release.
-COVERITY_EMAIL = [email protected]
-COVERITY_TARBALL = GraphicsMagick.xz
-COVERITY_VERSION = snapshot-@PACKAGE_CHANGE_DATE@
-COVERITY_DESCRIPTION = 'Ubuntu Q@QuantumDepth@'
-COVERITY_COV_INT = 'cov-int'
-
 # Rules for a profiled build (according to Paolo Bonzini <[email protected]>)
 #profile:
 #	$(MAKE) clean
@@ -11394,6 +11396,10 @@
 	  ) \
 	)
 
+# Special cleaning rules
+clean-local:
+	$(RM) -rf $(COVERITY_COV_INT)
+
 #
 # Additional install rules
 #
@@ -11479,10 +11485,12 @@
 @HasGRAPHICSMAGICK_SNAPSHOT_COPY_FALSE@	done
 @HasGRAPHICSMAGICK_SNAPSHOT_COPY_FALSE@	cp $(top_srcdir)/ChangeLog $(SNAPSHOT_DIRECTORY)/ChangeLog.txt
 @HasGRAPHICSMAGICK_SNAPSHOT_COPY_FALSE@	cp $(top_srcdir)/www/Changelog.html $(SNAPSHOT_DIRECTORY)/ChangeLog.html
-# New URL is https://scan.coverity.com/projects/graphicsmagick?tab=overview
+
+# Build under Coverity
 coverity:
 	$(MAKE) clean
-	cov-build --dir cov-int $(MAKE)
+	$(RM) -rf $(COVERITY_COV_INT)
+	cov-build --dir $(COVERITY_COV_INT) $(MAKE)
 	tar caf $(COVERITY_TARBALL) cov-int
 	curl --limit-rate 34K \
 	--form token=`cat $$HOME/.coverity_key_gm` \
@@ -11492,7 +11500,6 @@
 	--form description=$(COVERITY_DESCRIPTION) \
 	https://scan.coverity.com/builds?project=GraphicsMagick
 	$(RM) $(COVERITY_TARBALL)
-	$(RM) -rf $(COVERITY_COV_INT)
 
 # Build symbols files to add 'gm' prefix to functions
 gmsymbols:
diff -r 6233da622ab9 -r 8317983b3b31 coders/jpeg.c
--- a/coders/jpeg.c	Sat Dec 10 09:18:12 2022 -0600
+++ b/coders/jpeg.c	Sat Dec 10 11:03:37 2022 -0600
@@ -2165,19 +2165,21 @@
       *profile;
 
     size_t
+      alloc_length,
       length=0;
 
 
     length=Min(profile_length-i,65519);
-    profile=MagickAllocateResourceLimitedMemory(unsigned char *,length+14);
+    alloc_length=length+14;
+    profile=MagickAllocateResourceLimitedMemory(unsigned char *,alloc_length);
     if (profile == (unsigned char *) NULL)
       break;
-    (void) strlcpy((char *) profile,"ICC_PROFILE",sizeof(profile));
+    (void) strlcpy((char *) profile,"ICC_PROFILE",alloc_length);
     profile[12]=(unsigned char) ((i/65519)+1);
     profile[13]=(unsigned char) ((profile_length/65519)+1);
     for (j=0; j < (long) length; j++)
       profile[j+14]=color_profile[i+j];
-    jpeg_write_marker(jpeg_info,ICC_MARKER,profile,(unsigned int) length+14);
+    jpeg_write_marker(jpeg_info,ICC_MARKER,profile,(unsigned int) alloc_length);
     MagickFreeResourceLimitedMemory(profile);
   }
 }
diff -r 6233da622ab9 -r 8317983b3b31 coders/meta.c
--- a/coders/meta.c	Sat Dec 10 09:18:12 2022 -0600
+++ b/coders/meta.c	Sat Dec 10 11:03:37 2022 -0600
@@ -364,6 +364,9 @@
     {
       if (state == 0)
         {
+          size_t
+            name_alloc;
+
           int
             state,
             next;
@@ -389,10 +392,11 @@
                 recnum = MagickAtoI(newstr);
                 break;
               case 2:
-                name = MagickAllocateResourceLimitedMemory(char *,strlen(newstr)+1);
+                name_alloc = strlen(newstr)+1;
+                name = MagickAllocateResourceLimitedMemory(char *,name_alloc);
                 if (name == (char *) NULL)
                   goto parse8BIM_failure;
-                (void) strlcpy(name,newstr,sizeof(name));
+                (void) strlcpy(name,newstr,name_alloc);
                 break;
             }
             state++;
@@ -664,6 +668,9 @@
     {
       if (state == 0)
         {
+          size_t
+            name_alloc;
+
           int
             state,
             next;
@@ -689,10 +696,11 @@
                 recnum = MagickAtoI(newstr);
                 break;
               case 2:
-                name = MagickAllocateResourceLimitedMemory(char *,strlen(newstr)+1);
+                name_alloc = strlen(newstr)+1;
+                name = MagickAllocateResourceLimitedMemory(char *,name_alloc);
                 if (name == (char *) NULL)
                   goto parse8BIMW_failure;
-                (void) strlcpy(name,newstr,sizeof(name));
+                (void) strlcpy(name,newstr,name_alloc);
                 break;
             }
             state++;
diff -r 6233da622ab9 -r 8317983b3b31 magick/widget.c
--- a/magick/widget.c	Sat Dec 10 09:18:12 2022 -0600
+++ b/magick/widget.c	Sat Dec 10 11:03:37 2022 -0600
@@ -1734,7 +1734,7 @@
   /*
     Map Color Browser widget.
   */
-  (void) strlcpy(windows->widget.name,"Browse and Select a Color",sizeof(windows->widget.name));
+  (void) strlcpy(windows->widget.name,"Browse and Select a Color",MaxTextExtent);
   status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
   if (status != 0)
     {
@@ -2729,7 +2729,7 @@
   if (status != 0)
     return;
   MagickXNoticeWidget(display,windows,"Color is unknown to X server:",reply);
-  (void) strlcpy(reply,"gray",sizeof(reply));
+  (void) strlcpy(reply,"gray",MaxTextExtent);
 }
 
 /*
@@ -3267,7 +3267,7 @@
   /*
     Map Confirm widget.
   */
-  (void) strlcpy(windows->widget.name,"Confirm",sizeof(windows->widget.name));
+  (void) strlcpy(windows->widget.name,"Confirm",MaxTextExtent);
   status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
   if (status != 0)
     {
@@ -3674,7 +3674,7 @@
   /*
     Map Dialog widget.
   */
-  (void) strlcpy(windows->widget.name,"Dialog",sizeof(windows->widget.name));
+  (void) strlcpy(windows->widget.name,"Dialog",MaxTextExtent);
   status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
   if (status != 0)
     {
@@ -4311,7 +4311,7 @@
   /*
     Map File Browser widget.
   */
-  (void) strlcpy(windows->widget.name,"Browse and Select a File",sizeof(windows->widget.name));
+  (void) strlcpy(windows->widget.name,"Browse and Select a File",MaxTextExtent);
   status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
   if (status != 0)
     {
@@ -5565,7 +5565,7 @@
   /*
     Map Font Browser widget.
   */
-  (void) strlcpy(windows->widget.name,"Browse and Select a Font",sizeof(windows->widget.name));
+  (void) strlcpy(windows->widget.name,"Browse and Select a Font",MaxTextExtent);
   status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
   if (status != 0)
     {
@@ -6793,7 +6793,7 @@
   /*
     Map List Browser widget.
   */
-  (void) strlcpy(window_info->name,"Browse",sizeof(window_info->name));
+  (void) strlcpy(window_info->name,"Browse",MaxTextExtent);
   status=XStringListToTextProperty(&window_info->name,1,&window_name);
   if (status != 0)
     {
@@ -8172,7 +8172,7 @@
   /*
     Map Notice widget.
   */
-  (void) strlcpy(windows->widget.name,"Notice",sizeof(windows->widget.name));
+  (void) strlcpy(windows->widget.name,"Notice",MaxTextExtent);
   status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
   if (status != 0)
     {
@@ -8508,7 +8508,7 @@
   /*
     Map Preferences widget.
   */
-  (void) strlcpy(windows->widget.name,"Preferences",sizeof(windows->widget.name));
+  (void) strlcpy(windows->widget.name,"Preferences",MaxTextExtent);
   status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
   if (status != 0)
     {
diff -r 6233da622ab9 -r 8317983b3b31 www/Changelog.html
--- a/www/Changelog.html	Sat Dec 10 09:18:12 2022 -0600
+++ b/www/Changelog.html	Sat Dec 10 11:03:37 2022 -0600
@@ -40,6 +40,31 @@
 <p>2022-12-10  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>coders/meta.c (parse8BIM): Fix Coverity 382245 &quot;Incorrect
+expression (SIZEOF_MISMATCH)&quot;.
+(parse8BIMW): Fix Coverity 382250 &quot;Incorrect expression
+(SIZEOF_MISMATCH)&quot;.</p></li>
+<li><p>magick/widget.c (MagickXNoticeWidget): Fix Coverity 382254
+&quot;Incorrect expression (SIZEOF_MISMATCH).&quot;
+(MagickXFontBrowserWidget): Fix Coverity 382253 &quot;Incorrect
+expression (SIZEOF_MISMATCH)&quot;.
+(MagickXFileBrowserWidget): Fix Coverity 382252 &quot;Incorrect
+expression (SIZEOF_MISMATCH)&quot;.
+(MagickXPreferencesWidget): Fix Coverity 382251 &quot;Incorrect
+expression (SIZEOF_MISMATCH)&quot;.
+(MagickXConfirmWidget): Fix Coverity 382249 &quot;Incorrect expression
+(SIZEOF_MISMATCH)&quot;.
+(MagickXListBrowserWidget): Fix Coverity 382248 &quot;Incorrect
+expression (SIZEOF_MISMATCH)&quot;.
+(MagickXDialogWidget): Fix Coverity 382247 &quot;Incorrect expression
+(SIZEOF_MISMATCH)&quot;.
+(MagickXColorBrowserWidget): Fix Coverity 382246
+&quot;(SIZEOF_MISMATCH)&quot;.</p></li>
+<li><p>coders/jpeg.c (WriteICCProfile): Fix Coverity 382255 &quot;Incorrect
+expression (SIZEOF_MISMATCH)&quot;.</p></li>
+<li><p>Makefile.am (clean-local): Added a clean-local target to remove
+Coverity subdirectory ('cov-int').  Building with 'coverity'
+target leaves Coverity subdirectory in place for inspection.</p></li>
 <li><p>NEWS.txt: Updated the news.</p></li>
 </ul>
 </blockquote>
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.