From ff8f7134b39aa2fe4fe16fbda8ce58584f1dc645 Mon Sep 17 00:00:00 2001 From: dgp Date: Mon, 2 Jul 2012 16:22:18 +0000 Subject: 1189293 Make '<<' redirects binary safe. Don't use strlen() (or equivalent) to find end of written data bytes. --- unix/tclUnixPipe.c | 2 +- win/tclWinPipe.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/unix/tclUnixPipe.c b/unix/tclUnixPipe.c index 3a4005c..829a4a6 100644 --- a/unix/tclUnixPipe.c +++ b/unix/tclUnixPipe.c @@ -213,7 +213,7 @@ TclpCreateTempFile(contents) if (contents != NULL) { native = Tcl_UtfToExternalDString(NULL, contents, -1, &dstring); - if (write(fd, native, strlen(native)) == -1) { + if (write(fd, native, Tcl_DStringLength(&dstring)) == -1) { close(fd); Tcl_DStringFree(&dstring); return NULL; diff --git a/win/tclWinPipe.c b/win/tclWinPipe.c index 4c530e3..3a55abb 100644 --- a/win/tclWinPipe.c +++ b/win/tclWinPipe.c @@ -691,13 +691,15 @@ TclpCreateTempFile(contents) if (contents != NULL) { DWORD result, length; CONST char *p; + int toCopy; /* * Convert the contents from UTF to native encoding */ native = Tcl_UtfToExternalDString(NULL, contents, -1, &dstring); - for (p = native; *p != '\0'; p++) { + toCopy = Tcl_DStringLength(&dstring); + for (p = native; toCopy > 0; p++, toCopy--) { if (*p == '\n') { length = p - native; if (length > 0) { -- cgit v0.12