Skip to content

Commit

Permalink
Minor change to length limit checks
Browse files Browse the repository at this point in the history
  • Loading branch information
apnadkarni committed Apr 24, 2023
1 parent 44f92a9 commit 38ae218
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions generic/tclScan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 38ae218

Please sign in to comment.