summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Gerecke <killertofu@gmail.com>2015-04-09 16:35:36 -0700
committerJason Gerecke <killertofu@gmail.com>2015-04-28 10:09:51 -0700
commit162cf8d54e8858b8c1cbc96c49f4ffa73716b7e8 (patch)
treec9fc3e54630ecb507ef203d76aeeab9d93910e78
parent4416168933e058cee6a5e0df803c9c822f8fa63d (diff)
downloadxf86-input-wacom-162cf8d54e8858b8c1cbc96c49f4ffa73716b7e8.tar.gz
xsetwacom: Add ability to read args from stdin for fuzzing
Add a new "--enable-fuzz-interface" configuration option which will cause xsetwacom to read NUL-separated arguments from stdin (for example: `echo -en 'list\0devices' | xsetwacom`). This makes it easier to plug into fuzzing software for debugging. Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
-rw-r--r--configure.ac6
-rw-r--r--tools/Makefile.am4
-rw-r--r--tools/xsetwacom.c47
3 files changed, 57 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index ec04a2e..2244d16 100644
--- a/configure.ac
+++ b/configure.ac
@@ -106,6 +106,12 @@ AC_ARG_WITH([xorg-conf-dir],
AC_SUBST(configdir)
AM_CONDITIONAL(HAS_XORG_CONF_DIR, [test "x$configdir" != "x"])
+AC_ARG_ENABLE(fuzz-interface, AS_HELP_STRING([--enable-fuzz-interface],
+ [Enable xsetwacom to take NUL-separated commands from stdin (default: no)]),
+ [FUZZINTERFACE=$enableval],
+ [FUZZINTERFACE=no])
+AM_CONDITIONAL(FUZZINTERFACE, [test "x$FUZZINTERFACE" = xyes])
+
AC_ARG_ENABLE(unit-tests, AS_HELP_STRING([--enable-unit-tests],
[Enable unit-tests (default: auto)]),
[UNITTESTS=$enableval],
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 5622362..28c2fcd 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -35,6 +35,10 @@ xsetwacom_SOURCES = xsetwacom.c
xsetwacom_CFLAGS = $(X11_CFLAGS)
xsetwacom_LDADD = $(X11_LIBS)
+if FUZZINTERFACE
+xsetwacom_CFLAGS += -DBUILD_FUZZINTERFACE
+endif
+
if UNITTESTS
check_PROGRAMS = xsetwacom-test
xsetwacom_test_SOURCES=xsetwacom.c
diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c
index 1fd70c8..e9d455b 100644
--- a/tools/xsetwacom.c
+++ b/tools/xsetwacom.c
@@ -2697,6 +2697,49 @@ static void get_param(Display *dpy, XDevice *dev, param_t *param, int argc, char
#ifndef BUILD_TEST
+
+#ifdef BUILD_FUZZINTERFACE
+void argsfromstdin(int *argc, char ***argv)
+{
+ const int READSIZE = 256;
+ char *buf = strdup((*argv)[0]);
+ size_t len = strlen(buf)+1;
+
+ while (1) {
+ char *p = realloc(buf, len + READSIZE);
+ size_t n;
+
+ if (!p)
+ exit(1);
+ buf = p;
+
+ n = fread(buf+len, 1, READSIZE, stdin);
+ if (n > 0) {
+ len += n;
+ }
+ else {
+ buf[len] = '\0';
+ len++;
+ break;
+ }
+ }
+
+ *argc = 0;
+ *argv = NULL;
+ while (len) {
+ char **p = realloc(*argv, (*argc + 1) * sizeof(char**));
+ if (!p)
+ exit(1);
+ *argv = p;
+ (*argv)[*argc] = buf;
+ (*argc)++;
+
+ len -= strlen(buf) + 1;
+ buf += strlen(buf) + 1;
+ }
+}
+#endif /* BUILD_FUZZINTERFACE */
+
int main (int argc, char **argv)
{
int c;
@@ -2719,6 +2762,10 @@ int main (int argc, char **argv)
{NULL, 0, NULL, 0}
};
+#ifdef BUILD_FUZZINTERFACE
+ argsfromstdin(&argc, &argv);
+#endif /* BUILD FUZZINTERFACE */
+
if (argc < 2)
{
usage();