[rrd-developers] rrd_graph and rrd_set_error patches for longer filenames

Blair Zajac bzajac at geostaff.com
Mon Oct 11 03:42:28 MEST 1999


Hello,

I've been running into some problems with pathnames longer than 255
characters in rrd_graph.  The following patch fixes these and prevents
buffer overflows in rrd_set_error, unless the error is longer than
4096 characters.

Blair
-------------- next part --------------
diff -rc ../rrdtool-1.0.7.0/src/rrd_error.c ./src/rrd_error.c
*** ../rrdtool-1.0.7.0/src/rrd_error.c	Fri Aug 27 12:20:05 1999
--- ./src/rrd_error.c	Sun Oct 10 18:40:24 1999
***************
*** 16,28 ****
  void
  rrd_set_error(char *fmt, ...)
  {
!     int maxlen = strlen(fmt)*4;
      va_list argp;
      rrd_clear_error();
-     rrd_error = malloc(sizeof(char)*maxlen);
      va_start(argp, fmt);
!     vsprintf(rrd_error, fmt, argp);
      va_end(argp);
  }
  
  int
--- 16,29 ----
  void
  rrd_set_error(char *fmt, ...)
  {
!     static char buffer[4096];
      va_list argp;
      rrd_clear_error();
      va_start(argp, fmt);
!     vsprintf(buffer, fmt, argp);
      va_end(argp);
+     rrd_error = malloc(sizeof(char)*(strlen(buffer)+1));
+     strcpy(rrd_error, buffer);
  }
  
  int
diff -rc ../rrdtool-1.0.7.0/src/rrd_graph.c ./src/rrd_graph.c
*** ../rrdtool-1.0.7.0/src/rrd_graph.c	Fri Oct  1 12:15:28 1999
--- ./src/rrd_graph.c	Fri Oct  8 23:22:35 1999
***************
*** 180,186 ****
  
      /* configuration of graph */
  
!     char           graphfile[255]; /* filename for graphic */
      long           xsize,ysize;    /* graph area size in pixels */
      col_trip_t     graph_col[__GRC_END__]; /* real colors for the graph */   
      char           ylegend[200];   /* legend along the yaxis */
--- 180,186 ----
  
      /* configuration of graph */
  
!     char           graphfile[1024]; /* filename for graphic */
      long           xsize,ysize;    /* graph area size in pixels */
      col_trip_t     graph_col[__GRC_END__]; /* real colors for the graph */   
      char           ylegend[200];   /* legend along the yaxis */
***************
*** 2716,2723 ****
  	return -1;
      }
  
!     strncpy(im.graphfile,argv[optind],254);
!     im.graphfile[254]='\0';
  
      if (proc_start_end(&start_tv,&end_tv,&start_tmp,&end_tmp) == -1){
  	return -1;
--- 2716,2723 ----
  	return -1;
      }
  
!     strncpy(im.graphfile,argv[optind],sizeof(im.graphfile)-1);
!     im.graphfile[sizeof(im.graphfile)-1]='\0';
  
      if (proc_start_end(&start_tv,&end_tv,&start_tmp,&end_tmp) == -1){
  	return -1;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bzajac.vcf
Type: text/x-vcard
Size: 322 bytes
Desc: Card for Blair Zajac
Url : https://lists.oetiker.ch/pipermail/rrd-developers/attachments/19991010/0dc4b0f5/attachment.vcf 


More information about the rrd-developers mailing list