diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-06-16 19:01:46 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-06-16 19:01:46 +0200 |
commit | 202be57bb94b2bd65db9164bfd94ad2ec5167071 (patch) | |
tree | a3e9b3e1911dc04058d0a6b320da1763a2919cae /sys/src/libdraw/badrect.c | |
parent | e36d9f5c4e667970a4a7aa15744e304ccc7c58f3 (diff) |
draw: add badrect() function to reject zero, negative size or orverly huge rectangles
not checking the rectangle dimensions causes integer overflows
and memory corruption. adding a new badrect() function that checks
for these cases.
Diffstat (limited to 'sys/src/libdraw/badrect.c')
-rw-r--r-- | sys/src/libdraw/badrect.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sys/src/libdraw/badrect.c b/sys/src/libdraw/badrect.c new file mode 100644 index 000000000..5ec53edb4 --- /dev/null +++ b/sys/src/libdraw/badrect.c @@ -0,0 +1,22 @@ +#include <u.h> +#include <libc.h> +#include <draw.h> + +/* + * check for zero, negative size or insanely huge rectangle. + */ +int +badrect(Rectangle r) +{ + int x, y; + uint z; + + x = Dx(r); + y = Dy(r); + if(x > 0 && y > 0){ + z = x*y; + if(z/x == y && z < 0x10000000) + return 0; + } + return 1; +} |