From 22bed54a233c2bf15f51fd149e2059b59205be71 Mon Sep 17 00:00:00 2001 From: andreas_kupries Date: Wed, 9 Apr 2008 18:35:25 +0000 Subject: * generic/tclIOCmd.c (Tcl_FcopyObjCmd): Added checking of -size * tests/ioCmd.test (iocmd-15.{13,14}): value to reject negative values, and values overflowing 32-bit signed. [Bug 1557855]. Basic patch by Alexandre Ferrieux , with modifications from me to separate overflow from true negative value. Extended testsuite. --- ChangeLog | 9 +++++++++ generic/tclIOCmd.c | 16 +++++++++++++++- tests/ioCmd.test | 8 +++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 785741a..a4e3700 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-04-09 Andreas Kupries + + * generic/tclIOCmd.c (Tcl_FcopyObjCmd): Added checking of -size + * tests/ioCmd.test (iocmd-15.{13,14}): value to reject negative + values, and values overflowing 32-bit signed. [Bug 1557855]. Basic + patch by Alexandre Ferrieux , with + modifications from me to separate overflow from true negative + value. Extended testsuite. + 2008-04-08 Andreas Kupries * tests/io.test (io-53.8,53.9,53.10): Backported das' fix of typo diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c index 300bef0..48debd8 100644 --- a/generic/tclIOCmd.c +++ b/generic/tclIOCmd.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclIOCmd.c,v 1.15.2.3 2008/02/26 22:30:26 hobbs Exp $ + * RCS: @(#) $Id: tclIOCmd.c,v 1.15.2.4 2008/04/09 18:35:27 andreas_kupries Exp $ */ #include "tclInt.h" @@ -1542,6 +1542,20 @@ Tcl_FcopyObjCmd(dummy, interp, objc, objv) if (Tcl_GetIntFromObj(interp, objv[i+1], &toRead) != TCL_OK) { return TCL_ERROR; } + if (toRead<0) { + Tcl_WideInt w; + if (Tcl_GetWideIntFromObj(interp, objv[i+1], &w) != TCL_OK) { + return TCL_ERROR; + } + if (w >= (Tcl_WideInt)0) { + Tcl_AppendResult(interp, + "integer value to large to represent as 32bit signed value", + NULL); + } else { + Tcl_AppendResult(interp, "negative size forbidden", NULL); + } + return TCL_ERROR; + } break; case FcopyCommand: cmdPtr = objv[i+1]; diff --git a/tests/ioCmd.test b/tests/ioCmd.test index 29ddba7..979f3cc 100644 --- a/tests/ioCmd.test +++ b/tests/ioCmd.test @@ -13,7 +13,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: ioCmd.test,v 1.16.2.3 2006/03/16 18:23:24 andreas_kupries Exp $ +# RCS: @(#) $Id: ioCmd.test,v 1.16.2.4 2008/04/09 18:35:28 andreas_kupries Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -577,6 +577,12 @@ test iocmd-15.11 {Tcl_FcopyObjCmd} {fcopy} { test iocmd-15.12 {Tcl_FcopyObjCmd} {fcopy} { list [catch {fcopy $rfile $wfile -command bar -size foo} msg] $msg } {1 {expected integer but got "foo"}} +test iocmd-15.13 {Tcl_FcopyObjCmd} {fcopy} { + list [catch {fcopy $rfile $wfile -command bar -size 3221176172} msg] $msg +} {1 {integer value to large to represent as 32bit signed value}} +test iocmd-15.14 {Tcl_FcopyObjCmd} {fcopy} { + list [catch {fcopy $rfile $wfile -command bar -size -2} msg] $msg +} {1 {negative size forbidden}} close $rfile close $wfile -- cgit v0.12