Update of /cvsroot/pure-data/externals/iem/iemmatrix/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24664
Modified Files: mtx_matrix.c Log Message: hopefully made it a bit more secure...
Index: mtx_matrix.c =================================================================== RCS file: /cvsroot/pure-data/externals/iem/iemmatrix/src/mtx_matrix.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** mtx_matrix.c 29 Mar 2006 12:07:52 -0000 1.5 --- mtx_matrix.c 25 Jul 2006 14:13:28 -0000 1.6 *************** *** 19,22 **** --- 19,27 ----
#include "iemmatrix.h" + #include <stdio.h> + #ifdef _WIN32 + /* or should we use the security enhanced _snprintf_s() ?? */ + # define snprintf _snprintf + #endif
/* -------------------- matrix ------------------------------ */ *************** *** 443,447 ****
if (binbuf_read_via_path(bbuf, filename->s_name, canvas_getdir(x->x_canvas)->s_name, 0)) ! pd_error(x,"matrix: failed to read %s", filename->s_name);
ap=binbuf_getvec(bbuf); --- 448,452 ----
if (binbuf_read_via_path(bbuf, filename->s_name, canvas_getdir(x->x_canvas)->s_name, 0)) ! pd_error(x,"matrix: failed to read %128s", filename->s_name);
ap=binbuf_getvec(bbuf); *************** *** 458,462 **** { t_atom *ap=x->atombuffer+2; ! char filnam[MAXPDSTRING]; int rows = x->row, cols = x->col; FILE *f=0; --- 463,467 ---- { t_atom *ap=x->atombuffer+2; ! char *filnam = (char*)getbytes(sizeof(char)*MAXPDSTRING);; int rows = x->row, cols = x->col; FILE *f=0; *************** *** 466,470 **** /* open file */ if (!(f = fopen(filnam, "w"))) { ! pd_error(x,"matrix : failed to open %s", filnam); } else { char *text=(char *)getbytes(sizeof(char)*MAXPDSTRING); --- 471,475 ---- /* open file */ if (!(f = fopen(filnam, "w"))) { ! pd_error(x,"matrix : failed to open %128s", filnam); } else { char *text=(char *)getbytes(sizeof(char)*MAXPDSTRING); *************** *** 476,483 **** * applications such as octave */ ! sprintf(text, "#matrix %d %d\n", rows, cols); textlen = strlen(text); if (fwrite(text, textlen*sizeof(char), 1, f) < 1) { ! pd_error(x,"matrix : failed to write %s", filnam); goto end; }
--- 481,489 ---- * applications such as octave */ ! snprintf(text, MAXPDSTRING, "#matrix %d %d\n", rows, cols); ! text[MAXPDSTRING-1]=0; textlen = strlen(text); if (fwrite(text, textlen*sizeof(char), 1, f) < 1) { ! pd_error(x,"matrix : failed to write %128s", filnam); goto end; }
*************** *** 486,497 **** while (c--) { t_float val = atom_getfloat(ap++); ! sprintf(text, "%.15f ", val); textlen=strlen(text); if (fwrite(text, textlen*sizeof(char), 1, f) < 1) { ! pd_error(x,"matrix : failed to write %s", filnam); goto end; } } if (fwrite("\n", sizeof(char), 1, f) < 1) { ! pd_error(x, "matrix : failed to write %s", filnam); goto end; } } --- 492,504 ---- while (c--) { t_float val = atom_getfloat(ap++); ! snprintf(text, MAXPDSTRING, "%.15f ", val); ! text[MAXPDSTRING-1]=0; textlen=strlen(text); if (fwrite(text, textlen*sizeof(char), 1, f) < 1) { ! pd_error(x,"matrix : failed to write %128s", filnam); goto end; } } if (fwrite("\n", sizeof(char), 1, f) < 1) { ! pd_error(x, "matrix : failed to write %128s", filnam); goto end; } } *************** *** 502,505 **** --- 509,513 ---- /* close file */ if (f) fclose(f); + if(filnam)freebytes(filnam, sizeof(char)*MAXPDSTRING); }