Skip to content

Commit

Permalink
Fix overflow checking extension versions
Browse files Browse the repository at this point in the history
The easiest way to check for the version of an extension is to send the maximum
possible version numbers in the QueryVersion request. The X server overflows on
these as it assumes you will send a reasonable version number.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
(cherry picked from commit 548fc93)
  • Loading branch information
robert-ancell authored and whot committed Jun 26, 2014
1 parent 416ea95 commit 2ceb448
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions include/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,19 @@ extern void FormatDouble(double dbl, char *string);
* or a value greater than 0
*/
static inline int
version_compare(uint16_t a_major, uint16_t a_minor,
uint16_t b_major, uint16_t b_minor)
version_compare(uint32_t a_major, uint32_t a_minor,
uint32_t b_major, uint32_t b_minor)
{
int a, b;
if (a_major > b_major)
return 1;
if (a_major < b_major)
return -1;
if (a_minor > b_minor)
return 1;
if (a_minor < b_minor)
return -1;

a = a_major << 16 | a_minor;
b = b_major << 16 | b_minor;

return (a - b);
return 0;
}

/* some macros to help swap requests, replies, and events */
Expand Down

0 comments on commit 2ceb448

Please sign in to comment.