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.gere...@wacom.com>
---
 configure.ac      |  6 ++++++
 tools/Makefile.am |  4 ++++
 tools/xsetwacom.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+)

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();
-- 
2.3.5


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to