about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-10-07 20:20:08 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-10-07 20:20:08 +0000
commitf79daabd7540e5cc6c6a6cd128b884ea0de54906 (patch)
tree37f6e6b033fddb4ab7ae9023d4603f18229d2e5f
parent7fc46bb79f04fd0ba77284382c0ce4a74f34f2a3 (diff)
downloadnetpbm-mirror-f79daabd7540e5cc6c6a6cd128b884ea0de54906.tar.gz
netpbm-mirror-f79daabd7540e5cc6c6a6cd128b884ea0de54906.tar.xz
netpbm-mirror-f79daabd7540e5cc6c6a6cd128b884ea0de54906.zip
Release 10.84.02
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@3405 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--doc/HISTORY9
-rw-r--r--generator/pamtris/input.c20
-rw-r--r--lib/colorname.c5
-rw-r--r--lib/libpbmfont2.c2
-rw-r--r--lib/pm.h7
-rw-r--r--lib/pmfileio.c67
-rw-r--r--version.mk2
7 files changed, 104 insertions, 8 deletions
diff --git a/doc/HISTORY b/doc/HISTORY
index a9939dad..ba5b97da 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -4,6 +4,15 @@ Netpbm.
 CHANGE HISTORY 
 --------------
 
+not yet  BJH  Release 10.84.02
+
+              libnetpbm: Fix invalid memory reference in color name processing
+              when trivial memory allocation fails.
+
+              Build: fix reference to nonexistent getline on Mac OS X 10.6.
+
+              Build: fix reference to nonexistent strndup on Mac OS X 10.6.
+
 18.10.02 BJH  Release 10.84.01
 
               pamtojpeg2k: fix incorrect interpretation of -ilyrrates option
diff --git a/generator/pamtris/input.c b/generator/pamtris/input.c
index 166d6db5..4b7ff305 100644
--- a/generator/pamtris/input.c
+++ b/generator/pamtris/input.c
@@ -10,6 +10,7 @@
 #include <ctype.h>
 
 #include "netpbm/mallocvar.h"
+#include "netpbm/pm.h"
 
 #include "limits_pamtris.h"
 #include "framebuffer.h"
@@ -85,9 +86,8 @@ clear_attribs(state_info * const si,
 void
 init_input_processor(input_info * const ii) {
 
-    MALLOCARRAY_NOFAIL(ii->buffer, 128);
-
-    ii->length = 128;
+    ii->buffer = NULL;
+    ii->length = 0;
     ii->number = 1;
 }
 
@@ -95,7 +95,9 @@ init_input_processor(input_info * const ii) {
 
 void
 free_input_processor(input_info * const ii) {
-    free(ii->buffer);
+
+    if (ii->buffer)
+        free(ii->buffer);
 }
 
 
@@ -238,8 +240,14 @@ process_next_command(input_info           * const line,
         state.initialized = true;
     }
 
-    if (getline(&line->buffer, &line->length, stdin) == -1) {
-        return 0;
+    {
+        int eof;
+        size_t lineLen;
+
+        pm_getline(stdin, &line->buffer, &line->length, &eof, &lineLen);
+
+        if (eof)
+            return 0;
     }
 
     remove_comments(line->buffer);
diff --git a/lib/colorname.c b/lib/colorname.c
index 596d8788..c4d34fc2 100644
--- a/lib/colorname.c
+++ b/lib/colorname.c
@@ -200,6 +200,11 @@ pm_parse_dictionary_namen(char   const colorname[],
 
     fP = pm_openColornameFile(NULL, TRUE);  /* exits if error */
     canoncolor = strdup(colorname);
+
+    if (!canoncolor)
+        pm_error("Failed to allocate memory for %u-byte color name",
+                 (unsigned)strlen(colorname));
+
     pm_canonstr(canoncolor);
     gotit = FALSE;
     colorfileExhausted = FALSE;
diff --git a/lib/libpbmfont2.c b/lib/libpbmfont2.c
index e7189921..7f168648 100644
--- a/lib/libpbmfont2.c
+++ b/lib/libpbmfont2.c
@@ -749,7 +749,7 @@ doCharsetEncoding(Readline *    const readlineP,
         pm_message("CHARSET_ENCODING in BDF font file is too long. "
                    "Truncating");
 
-    *encodingP = strndup(readlineP->arg[1], maxTokenLen);
+    *encodingP = pm_strdup(readlineP->arg[1]);
     *gotEncodingP = true;
 }
 
diff --git a/lib/pm.h b/lib/pm.h
index 47cbfe83..81647873 100644
--- a/lib/pm.h
+++ b/lib/pm.h
@@ -373,6 +373,13 @@ char*
 pm_read_unknown_size(FILE * const ifP, 
                      long * const buf);
 
+void
+pm_getline(FILE *   const ifP,
+           char **  const bufferP,
+           size_t * const bufferSzP,
+           int *    const eofP,
+           size_t * const lineLenP);
+
 short
 pm_bs_short(short const s);
 
diff --git a/lib/pmfileio.c b/lib/pmfileio.c
index cfdac10d..31ec2588 100644
--- a/lib/pmfileio.c
+++ b/lib/pmfileio.c
@@ -839,6 +839,73 @@ pm_read_unknown_size(FILE * const file,
 
 
 
+void
+pm_getline(FILE *   const ifP,
+           char **  const bufferP,
+           size_t * const bufferSzP,
+           int *    const eofP,
+           size_t * const lineLenP) {
+/*----------------------------------------------------------------------------
+   This is like POSIX 'getline'.
+
+   But we don't include the newline in the returned line.
+-----------------------------------------------------------------------------*/
+    char * buffer;
+    size_t bufferSz;
+    bool gotLine;
+    bool eof;
+    size_t nReadSoFar;
+
+    buffer   = *bufferP;    /* initial value */
+    bufferSz = *bufferSzP;  /* initial value */
+
+    for (nReadSoFar = 0, gotLine = false, eof = false;
+         !gotLine && !eof; ) {
+
+        int rc;
+
+        rc = fgetc(ifP);
+
+        if (rc == EOF) {
+            if (ferror(ifP))
+                pm_error("Error reading input file.  fgets() failed with "
+                         "errno %d (%s)", errno, strerror(errno));
+
+            if (nReadSoFar == 0) {
+                /* Didn't get anything before EOF, so return EOF */
+                eof = true;
+            } else {
+                /* End of file ends the line */
+                gotLine = true;
+            }
+        } else {
+            char const c = (char)rc;
+
+            if (c == '\n') {
+                /* Newline ends the line, and is not part of it */
+                gotLine = true;
+            } else {
+                if (nReadSoFar + 2 > bufferSz) {
+                    /* + 2 = 1 for 'c', one for terminating NUL */
+                    bufferSz += 128;
+                    REALLOCARRAY(buffer, bufferSz);
+                }
+                buffer[nReadSoFar++] = c;
+            }
+        }
+    }
+
+    if (gotLine)
+        buffer[nReadSoFar] = '\0';
+
+    *eofP      = eof;
+    *bufferP   = buffer;
+    *bufferSzP = bufferSz;
+    *lineLenP  = nReadSoFar;
+}
+
+
+
 union cheat {
     uint32_t l;
     short s;
diff --git a/version.mk b/version.mk
index de529f9a..c9711da4 100644
--- a/version.mk
+++ b/version.mk
@@ -1,3 +1,3 @@
 NETPBM_MAJOR_RELEASE = 10
 NETPBM_MINOR_RELEASE = 84
-NETPBM_POINT_RELEASE = 1
+NETPBM_POINT_RELEASE = 2