summaryrefslogtreecommitdiffstats
path: root/win/tclWinDde.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-05-13 14:50:15 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-05-13 14:50:15 (GMT)
commitd7dccda78eed3f2ba6f123ccff8c61b9f7d4bfe0 (patch)
tree79ad65ea5c4785ef0ac8bdce1930e50858961204 /win/tclWinDde.c
parent31adc61af2686154ae232804fc282c663b57f8da (diff)
parent515c4f1a4cc29e7f4dd2fb0ca65aaec0e0172cab (diff)
downloadtcl-d7dccda78eed3f2ba6f123ccff8c61b9f7d4bfe0.zip
tcl-d7dccda78eed3f2ba6f123ccff8c61b9f7d4bfe0.tar.gz
tcl-d7dccda78eed3f2ba6f123ccff8c61b9f7d4bfe0.tar.bz2
Protect against receiving strings without ending \0, as external applications (or Tcl with TIP #106) could generate that.
Diffstat (limited to 'win/tclWinDde.c')
-rw-r--r--win/tclWinDde.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/win/tclWinDde.c b/win/tclWinDde.c
index 175b046..7e20da7 100644
--- a/win/tclWinDde.c
+++ b/win/tclWinDde.c
@@ -775,7 +775,10 @@ DdeServerProc(
utilString = (char *) DdeAccessData(hData, &dlen);
len = dlen;
- ddeObjectPtr = Tcl_NewStringObj(utilString, -1);
+ if (len && !utilString[len-1]) {
+ len--;
+ }
+ ddeObjectPtr = Tcl_NewStringObj(utilString, len);
Tcl_IncrRefCount(ddeObjectPtr);
DdeUnaccessData(hData);
if (convPtr->returnPackagePtr != NULL) {
@@ -1423,13 +1426,17 @@ DdeObjCmd(
result = TCL_ERROR;
} else {
DWORD tmp;
- const BYTE *dataString = DdeAccessData(ddeData, &tmp);
+ const char *dataString = (const char *) DdeAccessData(ddeData, &tmp);
if (binary) {
- returnObjPtr = Tcl_NewByteArrayObj(dataString,
+ returnObjPtr = Tcl_NewByteArrayObj((BYTE *) dataString,
(int) tmp);
} else {
- returnObjPtr = Tcl_NewStringObj((char *)dataString, -1);
+ if (tmp && !dataString[tmp-1]) {
+ --tmp;
+ }
+ returnObjPtr = Tcl_NewStringObj(dataString,
+ (int) tmp);
}
DdeUnaccessData(ddeData);
DdeFreeDataHandle(ddeData);