]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
src/rrd_graph_helper.c: fix Coverity CID#26523 Buffer not null terminated
authorMarek Schimara <Marek.Schimara@bull.net>
Thu, 16 Jun 2016 13:35:22 +0000 (15:35 +0200)
committerMarek Schimara <Marek.Schimara@bull.net>
Thu, 23 Jun 2016 14:32:33 +0000 (16:32 +0200)
        CWE-170 / https://cwe.mitre.org/data/definitions/170.html

src/rrd_graph_helper.c

index 422839f3e23620f32a4f4395c6d079afc3590e64..0f518eece1797ba23f0c52d87f1f1aff73f17dcb 100644 (file)
@@ -783,9 +783,18 @@ static graph_desc_t* newGraphDescription(image_desc_t *const im,enum gf_en gf,pa
   }
 
   /* and assign it */
-  if (vname) { strncpy(gdp->vname,vname,MAX_VNAME_LEN + 1);}
-  if (rrd) { strncpy(gdp->rrd,rrd,1024); }
-  if (ds) { strncpy(gdp->ds_nam,ds,DS_NAM_SIZE); }
+  if (vname) {
+    strncpy(gdp->vname,vname,MAX_VNAME_LEN);
+    gdp->vname[MAX_VNAME_LEN] = '\0';
+  }
+  if (rrd) {
+    strncpy(gdp->rrd,rrd, 1023);
+    gdp->rrd[1023] = '\0';
+  }
+  if (ds) {
+    strncpy(gdp->ds_nam,ds,DS_NAM_SIZE - 1);
+    gdp->ds_nam[DS_NAM_SIZE - 1] = '\0';
+  }
   if (cf) {
     gdp->cf=cf_conv(cf);
     if (((int)gdp->cf)==-1) {