From 38ae218f4a9c8e15aa3ab2822da49869f119dcf0 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Mon, 24 Apr 2023 13:54:33 +0000 Subject: [PATCH] Minor change to length limit checks --- generic/tclScan.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/generic/tclScan.c b/generic/tclScan.c index 07daadd4679..ecf841202da 100644 --- a/generic/tclScan.c +++ b/generic/tclScan.c @@ -353,15 +353,17 @@ ValidateFormat( */ if ((ch < 0x80) && isdigit(UCHAR(ch))) { /* INTL: "C" locale. */ - Tcl_WideInt wide; - wide = strtoll(format-1, (char **) &format, 10); /* INTL: "C" locale. */ - /* Note wide >= 0 because of isdigit check above */ - if (wide >= TCL_SIZE_MAX) { + /* Note ull >= 0 because of isdigit check above */ + unsigned long long ull; + ull = strtoull( + format - 1, (char **)&format, 10); /* INTL: "C" locale. */ + /* Note >=, not >, to leave room for a nul */ + if (ull >= TCL_SIZE_MAX) { Tcl_SetObjResult( interp, Tcl_ObjPrintf("specified field width %" TCL_LL_MODIFIER - "d exceeds limit %" TCL_SIZE_MODIFIER "d.", - wide, + "u exceeds limit %" TCL_SIZE_MODIFIER "d.", + ull, (Tcl_Size)TCL_SIZE_MAX-1)); Tcl_SetErrorCode( interp, "TCL", "FORMAT", "WIDTHLIMIT", NULL); @@ -703,10 +705,10 @@ Tcl_ScanObjCmd( */ if ((ch < 0x80) && isdigit(UCHAR(ch))) { /* INTL: "C" locale. */ - Tcl_WideInt wide; - wide = strtoll(format-1, (char **) &format, 10); /* INTL: "C" locale. */ - assert(wide <= TCL_SIZE_MAX); /* Else ValidateFormat should've error'ed */ - width = (Tcl_Size)wide; + unsigned long long ull; + ull = strtoull(format-1, (char **) &format, 10); /* INTL: "C" locale. */ + assert(ull <= TCL_SIZE_MAX); /* Else ValidateFormat should've error'ed */ + width = (Tcl_Size)ull; format += TclUtfToUniChar(format, &ch); } else { width = 0;