terminal: Don't crash when selecting non-ascii characters
authorDerek Foreman <derekf@osg.samsung.com>
Wed, 2 Sep 2015 21:21:54 +0000 (16:21 -0500)
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>
Thu, 10 Sep 2015 07:07:16 +0000 (10:07 +0300)
So it turns out if you cat /dev/urandom and drag select in the mess
you can crash weston-terminal.  There may also be more legitimate
ways of doing this.

The reason is that isalpha() and isdigit() only accept values that
fit within an unsigned char or are EOF.

By treating values < 0 the same as values > 127 we prevent this crash.

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
clients/terminal.c

index f1d8fc0..c5d5d60 100644 (file)
@@ -2579,7 +2579,7 @@ static int wordsep(int ch)
 {
        const char extra[] = "-,./?%&#:_=+@~";
 
-       if (ch > 127)
+       if (ch > 127 || ch < 0)
                return 1;
 
        return ch == 0 || !(isalpha(ch) || isdigit(ch) || strchr(extra, ch));