summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2017-05-05 17:12:52 (GMT)
committerdgp <dgp@users.sourceforge.net>2017-05-05 17:12:52 (GMT)
commitab808831bd7d76198dfc874049b9fd00b009646e (patch)
treea88cfd4f910da63336af1d7604d7ca26502b3099 /generic
parentd489f8278641d1b55d50c3800e86e567d7951153 (diff)
downloadtcl-ab808831bd7d76198dfc874049b9fd00b009646e.zip
tcl-ab808831bd7d76198dfc874049b9fd00b009646e.tar.gz
tcl-ab808831bd7d76198dfc874049b9fd00b009646e.tar.bz2
[6015221f59] Segfault after overflow of [binary] field specifier numeric count.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclBinary.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/generic/tclBinary.c b/generic/tclBinary.c
index 68289f2..cbe4970 100644
--- a/generic/tclBinary.c
+++ b/generic/tclBinary.c
@@ -1528,7 +1528,15 @@ GetFormatSpec(
(*formatPtr)++;
(*countPtr) = BINARY_ALL;
} else if (isdigit(UCHAR(**formatPtr))) { /* INTL: digit */
- (*countPtr) = strtoul(*formatPtr, formatPtr, 10);
+ unsigned long int count;
+
+ errno = 0;
+ count = strtoul(*formatPtr, formatPtr, 10);
+ if (errno || (count > (unsigned long) INT_MAX)) {
+ (*countPtr) = INT_MAX;
+ } else {
+ (*countPtr) = (int) count;
+ }
} else {
(*countPtr) = BINARY_NOCOUNT;
}