]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Stop using abs(unsigned) in X11 time comparison.
authorSimon Tatham <anakin@pobox.com>
Thu, 27 Aug 2015 17:39:36 +0000 (18:39 +0100)
committerSimon Tatham <anakin@pobox.com>
Thu, 27 Aug 2015 17:44:51 +0000 (18:44 +0100)
The validation end of XDM-AUTHORIZATION-1 needs to check that two
time_t values differ by at most XDM_MAXSKEW, which it was doing by
subtracting them and passing the result to abs(). This provoked a
warning from OS X's clang, on the reasonable enough basis that the
value passed to abs was unsigned.

Fixed by using the (well defined) unsigned arithmetic wraparound: to
check that the mathematical difference of two unsigned numbers is in
the interval [-k,+k], compute their difference _plus k_ as an
unsigned, and check the result is in the interval [0,2k] by doing an
unsigned comparison against 2k.

doc/udp.but
x11fwd.c

index f7640268ee5d8a03e3c5b028d60e15c8081168b7..c50464ee14991b3720d6fbf8974f724098e00396 100644 (file)
@@ -46,7 +46,9 @@ on 32-bit architectures \e{or bigger}; so it's safe to assume that
 by ANSI C.  Similarly, we assume that the execution character
 encoding is a superset of the printable characters of ASCII, though
 we don't assume the numeric values of control characters,
-particularly \cw{'\\n'} and \cw{'\\r'}.)
+particularly \cw{'\\n'} and \cw{'\\r'}. Also, the X forwarding code
+assumes that \c{time_t} has the Unix format and semantics, i.e. an
+integer giving the number of seconds since 1970.)
 
 \H{udp-multi-backend} Multiple backends treated equally
 
index e42edf7549dfebc937f1f3675bd6035f384c910f..6cfec72824304b8e853802b599c12ed932802a91 100644 (file)
--- a/x11fwd.c
+++ b/x11fwd.c
@@ -420,7 +420,8 @@ static const char *x11_verify(unsigned long peer_ip, int peer_port,
            if (data[i] != 0)          /* zero padding wrong */
                return "XDM-AUTHORIZATION-1 data failed check";
        tim = time(NULL);
-       if (abs(t - tim) > XDM_MAXSKEW)
+       if (((unsigned long)t - (unsigned long)tim
+             + XDM_MAXSKEW) > 2*XDM_MAXSKEW)
            return "XDM-AUTHORIZATION-1 time stamp was too far out";
        seen = snew(struct XDMSeen);
        seen->time = t;