summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2016-08-31 08:55:32 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2016-08-31 08:55:32 (GMT)
commit3710a862b304ce13a5d771616b45eaa556f201bc (patch)
treeb89107a81aaee65f22938a9b9f99531a9877eefd
parentb237ee23c355f68d92dccd811aa8bfd6f1ceed05 (diff)
parent34d8945d9d1dbbb3f599cabcad75ec0305f7615d (diff)
downloadtk-3710a862b304ce13a5d771616b45eaa556f201bc.zip
tk-3710a862b304ce13a5d771616b45eaa556f201bc.tar.gz
tk-3710a862b304ce13a5d771616b45eaa556f201bc.tar.bz2
Fix use of XMaxTransChars in stead of TCL_UTF_MAX in some places. This should prevent possible buffer overflow when TCL_UTF_MAX=6
Micro-optimizations in tkEntry and ttkEntry
-rw-r--r--generic/tkEntry.c5
-rw-r--r--generic/tkSelect.c2
-rw-r--r--generic/ttk/ttkEntry.c5
-rw-r--r--unix/tkUnixFont.c8
-rw-r--r--unix/tkUnixSelect.c4
-rw-r--r--win/tkWinFont.c2
-rw-r--r--win/tkWinKey.c4
-rw-r--r--win/tkWinX.c4
8 files changed, 18 insertions, 16 deletions
diff --git a/generic/tkEntry.c b/generic/tkEntry.c
index 5681e47..a66cf18 100644
--- a/generic/tkEntry.c
+++ b/generic/tkEntry.c
@@ -1927,7 +1927,7 @@ EntryComputeGeometry(
if (entryPtr->showChar != NULL) {
Tcl_UniChar ch;
- char buf[TCL_UTF_MAX];
+ char buf[4];
int size;
/*
@@ -1945,7 +1945,8 @@ EntryComputeGeometry(
entryPtr->displayString = p;
for (i = entryPtr->numChars; --i >= 0; ) {
- p += Tcl_UniCharToUtf(ch, p);
+ memcpy(p, buf, size);
+ p += size;
}
*p = '\0';
}
diff --git a/generic/tkSelect.c b/generic/tkSelect.c
index ab9018a..74b3964 100644
--- a/generic/tkSelect.c
+++ b/generic/tkSelect.c
@@ -26,7 +26,7 @@ typedef struct {
int charOffset; /* The offset of the next char to retrieve. */
int byteOffset; /* The expected byte offset of the next
* chunk. */
- char buffer[TCL_UTF_MAX]; /* A buffer to hold part of a UTF character
+ char buffer[4]; /* A buffer to hold part of a UTF character
* that is split across chunks. */
char command[1]; /* Command to invoke. Actual space is
* allocated as large as necessary. This must
diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c
index f395649..d80e1fd 100644
--- a/generic/ttk/ttkEntry.c
+++ b/generic/ttk/ttkEntry.c
@@ -283,14 +283,15 @@ static char *EntryDisplayString(const char *showChar, int numChars)
char *displayString, *p;
int size;
Tcl_UniChar ch;
- char buf[TCL_UTF_MAX];
+ char buf[4];
Tcl_UtfToUniChar(showChar, &ch);
size = Tcl_UniCharToUtf(ch, buf);
p = displayString = ckalloc(numChars * size + 1);
while (numChars--) {
- p += Tcl_UniCharToUtf(ch, p);
+ memcpy(p, buf, size);
+ p += size;
}
*p = '\0';
diff --git a/unix/tkUnixFont.c b/unix/tkUnixFont.c
index 1f4a1d4..a6826b5 100644
--- a/unix/tkUnixFont.c
+++ b/unix/tkUnixFont.c
@@ -513,7 +513,7 @@ Ucs2beToUtfProc(
srcEnd = src + srcLen;
dstStart = dst;
- dstEnd = dst + dstLen - TCL_UTF_MAX;
+ dstEnd = dst + dstLen - 4;
for (numChars = 0; src < srcEnd; numChars++) {
if (dst > dstEnd) {
@@ -588,7 +588,7 @@ UtfToUcs2beProc(
srcEnd = src + srcLen;
srcClose = srcEnd;
if (!(flags & TCL_ENCODING_END)) {
- srcClose -= TCL_UTF_MAX;
+ srcClose -= 4;
}
dstStart = dst;
@@ -2202,7 +2202,7 @@ FontMapLoadPage(
int row) /* Index of the page to be loaded into the
* cache. */
{
- char buf[16], src[TCL_UTF_MAX];
+ char buf[16], src[4];
int minHi, maxHi, minLo, maxLo, scale, checkLo;
int i, end, bitOffset, isTwoByteFont, n;
Tcl_Encoding encoding;
@@ -2406,7 +2406,7 @@ CanUseFallback(
unsigned bestScore[2];
char **nameList;
char **nameListOrig;
- char src[TCL_UTF_MAX];
+ char src[4];
FontAttributes want, got;
Display *display;
SubFont subFont;
diff --git a/unix/tkUnixSelect.c b/unix/tkUnixSelect.c
index 4bb462e..53275d1 100644
--- a/unix/tkUnixSelect.c
+++ b/unix/tkUnixSelect.c
@@ -21,7 +21,7 @@ typedef struct ConvertInfo {
* offset of the next chunk of data to
* transfer. */
Tcl_EncodingState state; /* The encoding state needed across chunks. */
- char buffer[TCL_UTF_MAX]; /* A buffer to hold part of a UTF character
+ char buffer[4]; /* A buffer to hold part of a UTF character
* that is split across chunks.*/
} ConvertInfo;
@@ -439,7 +439,7 @@ TkSelPropProc(
* Preserve any left-over bytes.
*/
- if (srcLen > TCL_UTF_MAX) {
+ if (srcLen > 4) {
Tcl_Panic("selection conversion left too many bytes unconverted");
}
memcpy(incrPtr->converts[i].buffer, src, (size_t) srcLen+1);
diff --git a/win/tkWinFont.c b/win/tkWinFont.c
index 7b5e4c9..10ea1b9 100644
--- a/win/tkWinFont.c
+++ b/win/tkWinFont.c
@@ -2188,7 +2188,7 @@ FontMapLoadPage(
{
FontFamily *familyPtr;
Tcl_Encoding encoding;
- char src[TCL_UTF_MAX], buf[16];
+ char src[XMaxTransChars], buf[16];
USHORT *startCount, *endCount;
int i, j, bitOffset, end, segCount;
diff --git a/win/tkWinKey.c b/win/tkWinKey.c
index ed546f7..5591133 100644
--- a/win/tkWinKey.c
+++ b/win/tkWinKey.c
@@ -102,7 +102,7 @@ TkpGetString(
*/
int unichar;
- char buf[TCL_UTF_MAX];
+ char buf[XMaxTransChars];
int len;
unichar = keyEv->trans_chars[1] & 0xff;
@@ -129,7 +129,7 @@ TkpGetString(
if (((keysym != NoSymbol) && (keysym > 0) && (keysym < 256))
|| (keysym == XK_Return) || (keysym == XK_Tab)) {
- char buf[TCL_UTF_MAX];
+ char buf[XMaxTransChars];
int len;
len = Tcl_UniCharToUtf((Tcl_UniChar) (keysym & 255), buf);
diff --git a/win/tkWinX.c b/win/tkWinX.c
index 7e25826..21c607c 100644
--- a/win/tkWinX.c
+++ b/win/tkWinX.c
@@ -1215,13 +1215,13 @@ GenerateXEvent(
break;
case WM_UNICHAR: {
- char buffer[TCL_UTF_MAX+1];
+ char buffer[XMaxTransChars];
int i;
event.type = KeyPress;
event.xany.send_event = -3;
event.xkey.keycode = wParam;
event.xkey.nbytes = Tcl_UniCharToUtf((int)wParam, buffer);
- for (i=0; i<event.xkey.nbytes && i<TCL_UTF_MAX; ++i) {
+ for (i=0; i<event.xkey.nbytes && i<XMaxTransChars; ++i) {
event.xkey.trans_chars[i] = buffer[i];
}
Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);