GraphicsMagick: ExpandFilename(): Handle the case where sysconf(...

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.8089.1691595113.8047.graphicsmagick-commit@lists.sourceforge.net>
changeset c569746bc87e in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=c569746bc87e
summary: ExpandFilename(): Handle the case where sysconf() returns a negative value.

diffstat:

 ChangeLog          |   7 +++++++
 magick/utility.c   |  11 +++++++++--
 www/Changelog.html |   9 +++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)

diffs (65 lines):

diff -r a09d4fd21fc0 -r c569746bc87e ChangeLog
--- a/ChangeLog	Wed Aug 09 09:34:54 2023 -0500
+++ b/ChangeLog	Wed Aug 09 10:31:43 2023 -0500
@@ -1,3 +1,10 @@
+2023-08-09  Bob Friesenhahn  <[email protected]>
+
+	* magick/utility.c (ExpandFilename): sysconf() can return a
+	negative value (e.g. -1).  Verify that the value is greater than 0
+	before using it.  Addresses Coverity 384798 "Out-of-bounds
+	access".
+
 2023-08-09  Fojtik Jaroslav  <[email protected]>
 
 	* coders/bmp.c: 64 bytes for BMP header is reserved for OS/2
diff -r a09d4fd21fc0 -r c569746bc87e magick/utility.c
--- a/magick/utility.c	Wed Aug 09 09:34:54 2023 -0500
+++ b/magick/utility.c	Wed Aug 09 10:31:43 2023 -0500
@@ -831,11 +831,14 @@
       struct  passwd
         pwd;
 
+      long
+        pwnam_buf_len_s;
+
       size_t
         pwnam_buf_len;
 
       char
-        *pwnam_buf;
+        *pwnam_buf = (char *) NULL;
 #  endif /* if defined(HAVE_GETPWNAM_R) */
 
       struct passwd
@@ -851,7 +854,11 @@
 
 #  if defined(HAVE_GETPWNAM_R)
       entry=(struct passwd *) NULL;
-      pwnam_buf_len = sysconf(_SC_GETPW_R_SIZE_MAX);
+      errno = 0;
+      pwnam_buf_len_s = sysconf(_SC_GETPW_R_SIZE_MAX);
+      if (pwnam_buf_len_s <= 0)
+        return;
+      pwnam_buf_len = (size_t) pwnam_buf_len_s;
       pwnam_buf=MagickAllocateMemory(char *,pwnam_buf_len);
       if (pwnam_buf != (char *) NULL)
         (void) getpwnam_r(username,&pwd,pwnam_buf,pwnam_buf_len,&entry);
diff -r a09d4fd21fc0 -r c569746bc87e www/Changelog.html
--- a/www/Changelog.html	Wed Aug 09 09:34:54 2023 -0500
+++ b/www/Changelog.html	Wed Aug 09 10:31:43 2023 -0500
@@ -37,6 +37,15 @@
 </div>
 
 <div class="document">
+<p>2023-08-09  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/utility.c (ExpandFilename): sysconf() can return a
+negative value (e.g. -1).  Verify that the value is greater than 0
+before using it.  Addresses Coverity 384798 &quot;Out-of-bounds
+access&quot;.</p></li>
+</ul>
+</blockquote>
 <p>2023-08-09  Fojtik Jaroslav  &lt;<a class="reference external" href="mailto:JaFojtik&#37;&#52;&#48;yandex&#46;com">JaFojtik<span>&#64;</span>yandex<span>&#46;</span>com</a>&gt;</p>
 <blockquote>
 <ul class="simple">
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.