Tcl Source Code

Artifact [40aa250edb]
Login

Artifact 40aa250edb8b823934c8c6af00c352cf54f4212c94cdd95443b8c1b60ee57055:

Attachment "0002-tclInterp.c-use-Tcl_WideInt-for-seconds-in-ChildTime.patch" to ticket [86dd172271] added by kanavin 2023-08-23 13:42:10. (unpublished)
From e7f03ca4d2c43b19fec32f158c9e3c49572dd88b Mon Sep 17 00:00:00 2001
From: Alexander Kanavin <[email protected]>
Date: Fri, 18 Aug 2023 18:09:01 +0200
Subject: [PATCH] tclInterp.c: use Tcl_WideInt for seconds in
 ChildTimeLimitCmd()

tmp variable is plain int, and so will overflow in 2038, even on
64 bit systems. This can be easily seen by setting system date to i.e. 2040
and running interp.test which would fail in several places.

---
 generic/tclInterp.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/generic/tclInterp.c b/generic/tclInterp.c
index 11202ce..c0359f0 100644
--- a/generic/tclInterp.c
+++ b/generic/tclInterp.c
@@ -4745,22 +4745,23 @@ ChildTimeLimitCmd(
 		limitMoment.usec = ((long) tmp)*1000;
 		break;
 	    case OPT_SEC:
+		Tcl_WideInt tmp_sec;
 		secObj = objv[i+1];
 		(void) Tcl_GetStringFromObj(objv[i+1], &secLen);
 		if (secLen == 0) {
 		    break;
 		}
-		if (TclGetIntFromObj(interp, objv[i+1], &tmp) != TCL_OK) {
+		if (TclGetWideIntFromObj(interp, objv[i+1], &tmp_sec) != TCL_OK) {
 		    return TCL_ERROR;
 		}
-		if (tmp < 0) {
+		if (tmp_sec < 0) {
 		    Tcl_SetObjResult(interp, Tcl_NewStringObj(
 			    "seconds must be at least 0", -1));
 		    Tcl_SetErrorCode(interp, "TCL", "OPERATION", "INTERP",
 			    "BADVALUE", NULL);
 		    return TCL_ERROR;
 		}
-		limitMoment.sec = tmp;
+		limitMoment.sec = tmp_sec;
 		break;
 	    }
 	}