From 9cf390b03bffcfffe9aaafa5e27adbc0d6a282b1 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Sun, 4 Feb 2024 18:02:10 -0500 Subject: More checking for geometry. --- xdeadzone.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/xdeadzone.c b/xdeadzone.c index dc787d1..83d805f 100644 --- a/xdeadzone.c +++ b/xdeadzone.c @@ -78,8 +78,9 @@ void set_corner(const char *geom) { corner = geom; } -/* XParseGeometry doesn't do enough error checking. It'll allow - stuff like 100x100x100, or 100x100+foo, with no complaint. */ +/* preparse geometry, because XParseGeometry doesn't do enough error + checking. It'll allow stuff like 100x100x100, or 100x100+foo, + or 64x-64-64, with no complaint. */ void preparse_geom(const char *geom) { int x_count = 0, plus_minus_count = 0, bogus_count = 0, len = 0; const char *p = geom; @@ -97,8 +98,14 @@ void preparse_geom(const char *geom) { if(!x_count) errmsg("bad geometry: no 'x' character"); + else if(len < 3) + errmsg("bad geometry: must be at least 3 characters"); + else if(len > 28) /* allows for 6-digit x/y/w/h */ + errmsg("bad geometry: string too long"); else if(x_count > 1) errmsg("bad geometry: multiple 'x' characters"); + else if(plus_minus_count == 1) + errmsg("bad geometry: missing +/- character in position"); else if(plus_minus_count > 2) errmsg("bad geometry: too many +/- characters"); else if(bogus_count) @@ -162,7 +169,7 @@ int main(int argc, char **argv) { if(corner) { if(strchr(geom, '+') || strchr(geom, '-')) - errmsg("bad geometry: X and Y position not allowed with -ne -nw -se -sw"); + errmsg("bad geometry: X and Y positions not allowed with -ne -nw -se -sw"); else strncat(geom, corner, GEOM_LEN); } @@ -179,6 +186,12 @@ int main(int argc, char **argv) { if(width == 0 || height == 0) errmsg("bad geometry: width and height must be non-zero"); + if((int)width < 0 || (int)height < 0) + errmsg("bad geometry: width and height may not be negative"); + + if(!corner && !(gflags & XValue) && !(gflags & YValue)) + errmsg("bad geometry: X and Y positions must be given, with absolute positioning"); + if(!(d = XOpenDisplay(NULL))) errmsg("can't open X display"); -- cgit v1.2.3