Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2003-10-22
06:26 • Closed ticket [805605ffff]: incorrect use of isspace in tclWinPipe.c plus 7 ... artifact: ef838dd665 user: andreas_kupries
2003-10-03
04:52 • Ticket [805605ffff]: 1 change artifact: 9d70265db3 user: dgp
2003-09-14
01:16 • Ticket [805605ffff]: 2 changes artifact: 10270af77f user: dkf
2003-09-13
14:02 • New ticket [805605ffff]. artifact: 0a3c208828 user: ronaldd

incorrect use of isspace in tclWinPipe.c

Closed / Fixed805605ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2003-09-13 14:02:53
Applies to Tcl Version 8.4.4 

In tclWinPipe.c, Line 1588
if (isspace(*start)) { /* INTL: ISO space. */
a signed char is passed to isspace.  

For two reasons, this is incorrect:

1. The string pointed to by 'start' is 
suppoed to be UTF-8. It does not make 
sense to pass the bytes of an UTF-8 
string to isspace unless they represent 
a single character (i. e. are in the 
range 1 - 127)

2. Passing a negative value (*start is a 
signed char!) to isspace causes the VC6 
and VC.NET runtime libraries to access 
memory outside the lookup-table used by 
the ctype.h functions.

Symptoms and consequences:
1. Access to undefined memory locations
2. Arguments may be quoted unneccessarily 
   (because isspace returns incorrectly true)
3. Assertion fails in Debug builds of 
   VC.NET 2003 in main.test (e. g. Main-1.3)
   "File istype.c, Line 68:
    Expression (unsigned)(c+1) <= 256"

How to reproduce:
for 1.: Assembly level debugger or code inspection 
         (ctype.h for VC6, istype.c for VC.NET 2003)
for 2.: Code inspection
for 3.: with VC.NET run
nmake -f makefile.vc OPTS=threads,symbols
nmake -f makefile.vc OPTS=threads,symbols test
The assertion should produce four dialog boxes

How to fix:
The following changes work for VC.NET and should be
portable across all compilers:
--- tclWinPipe.c-orig   2003-09-13 15:46:04
+++ tclWinPipe.c        2003-09-13 15:48:47
@@ -1584,8 +1584,11 @@
        if (arg[0] == '\0') {
            quote = 1;
        } else {
-           for (start = arg; *start != '\0'; start++) {
-               if (isspace(*start)) { /* INTL: ISO
space. */
+           int count;
+           for (start = arg; *start != '\0'; start +=
count) {
+               Tcl_UniChar ch;
+               count = Tcl_UtfToUniChar(start, &ch);
+               if (Tcl_UniCharIsSpace(ch)) { /* INTL:
ISO space. */
                    quote = 1;
                    break;
                }
dkf Ticket [805605ffff]: 2 changes [History diff]2003-09-14 01:16:05
dgp Ticket [805605ffff]: 1 change [History diff]2003-10-03 04:52:30
andreas_kupriesplain2003-10-22 06:26:08
Logged In: YES 
user_id=75003

Change accepted and committed to head of 8.4 branch.

One small change: 'Tcl_Unichar ch' was moved outside of the 
for loop, just before the loop, after the 'int count'.

And committed into the head.
Log in (anonymous is fine) to add a comment.