From 6b4dd8d597f4aa52599305dfaf5af19054b4422c Mon Sep 17 00:00:00 2001 From: Anton Lundin Date: Thu, 10 Jul 2014 21:37:29 +0200 Subject: Don't trust isspace() unless isascii() approves We have seen isspace(0xC3) return true on windows so we need to do something about this. As a wise man said: Using "isspace()" and friends on anything but the 0-127 range is just fraught with danger, regardless of platform. We remedy this by checking that isascii() says that its a 7-bit ascii character, something isspace() knows how to handle Signed-off-by: Anton Lundin Signed-off-by: Dirk Hohndel --- save-xml.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/save-xml.c b/save-xml.c index 9c802b82a..0a76753c6 100644 --- a/save-xml.c +++ b/save-xml.c @@ -35,12 +35,15 @@ static void show_utf8(struct membuffer *b, const char *text, const char *pre, co if (!text) return; /* remove leading and trailing space */ - while (isspace(*text)) + /* We need to combine isascii() with isspace(), + * because we can only trust isspace() with 7-bit ascii, + * on windows for example */ + while (isascii(*text) && isspace(*text)) text++; len = strlen(text); if (!len) return; - while (len && isspace(text[len - 1])) + while (len && isascii(text[len - 1]) && isspace(text[len - 1])) len--; /* strndup would be easier, but that doesn't appear to exist on Windows / Mac */ cleaned = strdup(text); -- cgit v1.2.3-70-g09d2