[gs-commits] ghostpdl branch, master, updated. jbig2dec-0.14-1742-g6d7243c

[email protected] (Chris Liddell) Wed, 23 Oct 2019 08:51:04 +0000 (UTC)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
The ghostpdl branch, master has been updated
       via  6d7243cea061373f592a6d9113626393ff0eb7d8 (commit)
      from  a34130a136fa9a61af3991224438dbf31b834767 (commit)

----------------------------------------------------------------------
commit 6d7243cea061373f592a6d9113626393ff0eb7d8
Author: Chris Liddell <[email protected]>
Date:   Wed Oct 23 09:39:11 2019 +0100

    Coverity ID 350179: Add buffer size check for string
    
    Before we append chars to a string buffer, check it's large enough

diff --git a/base/genconf.c b/base/genconf.c
index 7537099..de9afc9 100644
--- a/base/genconf.c
+++ b/base/genconf.c
@@ -353,7 +353,7 @@ static void mfree (void *om, const char *label);
 int alloc_list(string_list_t *);
 void free_list(string_list_t * list);
 
-void dev_file_name(char *);
+void dev_file_name(char *, int);
 int process_replaces(config_t *);
 int read_dev(config_t *, const char *);
 int read_token(char *, int, const char **);
@@ -681,11 +681,12 @@ free_list(string_list_t * list)
 
 /* If necessary, convert a .dev name to its file name. */
 void
-dev_file_name(char *str)
+dev_file_name(char *str, int bufsize)
 {
     int len = strlen(str);
 
-    if (len <= 4 || strcmp(".dev", str + len - 4))
+    if ((len <= 4 || strcmp(".dev", str + len - 4))
+        && bufsize > len + 4)
         strcat(str, ".dev");
 }
 
@@ -701,7 +702,7 @@ process_replaces(config_t * pconf)
 
         strncpy(bufname, pconf->replaces.items[i].str, MAX_STR);
         /* See if the file being replaced was included. */
-        dev_file_name(bufname);
+        dev_file_name(bufname, MAX_STR + 1);
         for (j = 0; j < pconf->file_names.count; ++j) {
             const char *fname = pconf->file_names.items[j].str;
 
@@ -968,7 +969,7 @@ pre:		sprintf(templat, pat, pconf->name_prefix);
                     pat = "image_type_(%%s,%simage_type_%%s)";
                 } else if (IS_CAT("include")) {
                     strcpy(str, item);
-                    dev_file_name(str);
+                    dev_file_name(str, MAX_STR);
                     return read_dev(pconf, str);
                 } else if (IS_CAT("init")) {
                     pat = "init_(%s%%s_init)";


Summary of changes:
 base/genconf.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)