Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9028
Modified Files: Tag: devel_0_37 t_tkcmd.c Log Message: tcl_vmess(): fixed buffer overflow pdgui_doevalfile(): print loadtime tcl error messages
Index: t_tkcmd.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/t_tkcmd.c,v retrieving revision 1.1.1.4 retrieving revision 1.1.1.4.2.1 diff -C2 -d -r1.1.1.4 -r1.1.1.4.2.1 *** t_tkcmd.c 9 May 2003 16:03:44 -0000 1.1.1.4 --- t_tkcmd.c 25 Oct 2004 15:16:14 -0000 1.1.1.4.2.1 *************** *** 296,318 **** }
! /* LATER should do a bounds check -- but how do you get printf to do that? */ void tcl_vmess(char *fmt, ...) { ! int result, i; ! char buf[MAXWRITE]; va_list ap;
va_start(ap, fmt); ! ! vsprintf(buf, fmt, ap); ! result = Tcl_Eval(tk_myinterp, buf); if (result != TCL_OK) { if (*tk_myinterp->result) printf("%s\n", tk_myinterp->result); } ! va_end(ap); }
#ifdef UNIX void pdgui_doevalfile(Tcl_Interp *interp, char *s) { --- 296,325 ---- }
! /* buffer overflow handler by matju */ void tcl_vmess(char *fmt, ...) { ! int result, n; ! char buf[MAXWRITE], *buf2=buf; va_list ap;
va_start(ap, fmt); ! n = vsnprintf(buf, sizeof(buf), fmt, ap); ! va_end(ap); ! if (n>=(int)sizeof(buf)) { ! buf2 = malloc(n+1); ! va_start(ap, fmt); ! n = vsprintf(buf2, fmt, ap); ! va_end(ap); ! } ! result = Tcl_Eval(tk_myinterp, buf2); if (result != TCL_OK) { if (*tk_myinterp->result) printf("%s\n", tk_myinterp->result); } ! if (buf!=buf2) free(buf2); }
#ifdef UNIX + /* matju's version (added error reporting) */ void pdgui_doevalfile(Tcl_Interp *interp, char *s) { *************** *** 320,333 **** sprintf(buf, "set pd_guidir "%s"\n", pdgui_path); tcl_mess(buf); ! strcpy(buf, pdgui_path); ! strcat(buf, "/bin/"); ! strcat(buf, s); ! if (Tcl_EvalFile(interp, buf) != TCL_OK) ! { ! char buf2[1000]; ! sprintf(buf2, "puts [concat tcl: %s: can't open script]\n", ! buf); ! tcl_mess(buf2); ! } }
--- 327,333 ---- sprintf(buf, "set pd_guidir "%s"\n", pdgui_path); tcl_mess(buf); ! sprintf(buf, "source %s/bin/%s",pdgui_path,s); ! if (Tcl_Eval(interp, buf) != TCL_OK) ! Tcl_Eval(tk_myinterp, "global errorInfo; puts stderr "Tcl Error: $errorInfo""); }