Add/replace checks in functions to ensure that they have the right number of arguments to do their job properly. The worst offender here was the set() function -- providing too many arguments would result in it walking off the end of data structures (often resulting in a segfault)
Signed-off-by: Jason Gerecke <killert...@gmail.com> --- tools/xsetwacom.c | 60 +++++++++++++++++++++++++++++++--------------------- 1 files changed, 36 insertions(+), 24 deletions(-) diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c index ae35996..d99a671 100644 --- a/tools/xsetwacom.c +++ b/tools/xsetwacom.c @@ -1349,14 +1349,14 @@ static void map_actions(Display *dpy, XDevice *dev, param_t* param, int argc, ch return; } - if (strcmp(param->prop_name, WACOM_PROP_BUTTON_ACTIONS) == 0) + if (argc < param->arg_count) { - if (argc == 0) - { - fprintf(stderr, "Too few arguments provided.\n"); - return; - } + fprintf(stderr, "Too few arguments provided.\n"); + return; + } + if (strcmp(param->prop_name, WACOM_PROP_BUTTON_ACTIONS) == 0) + { if (sscanf(argv[0], "%d", &offset) != 1) { fprintf(stderr, "'%s' is not a valid button number.\n", argv[0]); @@ -1379,9 +1379,10 @@ static void set_xydefault(Display *dpy, XDevice *dev, param_t* param, int argc, unsigned long nitems, bytes_after; long *ldata; - if (argc != 0) + if (argc != param->arg_count) { - fprintf(stderr, "Incorrect number of arguments supplied.\n"); + fprintf(stderr, "'%s' requires exactly %d value(s).\n", param->name, + param->arg_count); return; } @@ -1418,9 +1419,11 @@ out: static void set_mode(Display *dpy, XDevice *dev, param_t* param, int argc, char **argv) { int mode = Absolute; - if (argc < 1) + + if (argc != param->arg_count) { - usage(); + fprintf(stderr, "'%s' requires exactly %d value(s).\n", param->name, + param->arg_count); return; } @@ -1449,8 +1452,12 @@ static void set_rotate(Display *dpy, XDevice *dev, param_t* param, int argc, cha unsigned char* data; unsigned long nitems, bytes_after; - if (argc != 1) - goto error; + if (argc != param->arg_count) + { + fprintf(stderr, "'%s' requires exactly %d value(s).\n", param->name, + param->arg_count); + return; + } TRACE("Rotate '%s' for device %ld.\n", argv[0], dev->device_id); @@ -1493,10 +1500,6 @@ static void set_rotate(Display *dpy, XDevice *dev, param_t* param, int argc, cha XFlush(dpy); return; - -error: - fprintf(stderr, "Usage: xsetwacom <device name> Rotate [none | cw | ccw | half]\n"); - return; } @@ -1607,6 +1610,13 @@ static void set(Display *dpy, int argc, char **argv) values = strjoinsplit(argc - 2, &argv[2], &nvals); + if (nvals != param->arg_count) + { + fprintf(stderr, "'%s' requires exactly %d value(s).\n", param->name, + param->arg_count); + goto out; + } + for (i = 0; i < nvals; i++) { Bool success; @@ -1914,14 +1924,15 @@ static void get_map(Display *dpy, XDevice *dev, param_t *param, int argc, char** TRACE("Getting button map for device %ld.\n", dev->device_id); - if (strcmp(param->prop_name, WACOM_PROP_BUTTON_ACTIONS) == 0) + if (argc != param->arg_count) { - if (argc == 0) - { - fprintf(stderr, "Too few arguments provided.\n"); - return; - } + fprintf(stderr, "'%s' requires exactly %d value(s).\n", param->name, + param->arg_count); + return; + } + if (strcmp(param->prop_name, WACOM_PROP_BUTTON_ACTIONS) == 0) + { if (sscanf(argv[0], "%d", &offset) != 1) { fprintf(stderr, "'%s' is not a valid button number.\n", argv[0]); @@ -2005,9 +2016,10 @@ static void set_output(Display *dpy, XDevice *dev, param_t *param, int argc, cha XRROutputInfo *output_info; XRRCrtcInfo *crtc_info; - if (argc != 1) + if (argc != param->arg_count) { - fprintf(stderr, "Incorrect number of arguments supplied.\n"); + fprintf(stderr, "'%s' requires exactly %d value(s).\n", param->name, + param->arg_count); return; } -- 1.7.4.1 ------------------------------------------------------------------------------ Create and publish websites with WebMatrix Use the most popular FREE web apps or write code yourself; WebMatrix provides all the features you need to develop and publish your website. http://p.sf.net/sfu/ms-webmatrix-sf _______________________________________________ Linuxwacom-devel mailing list Linuxwacom-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel