chiark / gitweb /
test-example: Provide a fuzzer for the slip decoder base.ipv6-3.v2 proposed.fuzz-slip-decoder.2 proposed.fuzz-slip-decoder.v2
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Sep 2014 16:53:41 +0000 (17:53 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 27 Sep 2014 12:32:40 +0000 (13:32 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
test-example/outside-random.conf [new file with mode: 0644]
test-example/random-fake-userv [new file with mode: 0755]

diff --git a/test-example/outside-random.conf b/test-example/outside-random.conf
new file mode 100644 (file)
index 0000000..5c23920
--- /dev/null
@@ -0,0 +1,16 @@
+netlink userv-ipif {
+       name "netlink-ipif"; # Printed in log messages from this netlink
+       local-address "172.18.232.1";
+       secnet-address "172.18.232.2";
+       remote-networks "172.18.232.0/28";
+       mtu 1400;
+       buffer sysbuffer(2048);
+       userv-path "test-example/random-fake-userv";
+};
+comm udp {
+       port 16900;
+       buffer sysbuffer(4096);
+};
+local-name "test-example/outside/outside";
+local-key rsa-private("test-example/outside.key");
+include test-example/common.conf
diff --git a/test-example/random-fake-userv b/test-example/random-fake-userv
new file mode 100755 (executable)
index 0000000..cccd22c
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/perl -w
+
+use strict;
+use POSIX;
+
+open R, '/dev/urandom' or die $!;
+
+system 'cat >/dev/null &';
+
+sub randbytes ($) {
+    my ($count) = @_;
+    my $s;
+    my $r = read R, $s, $count;
+    die $! unless $r==$count;
+    return $s;
+}
+
+sub randbyteval () {
+    my $b = randbytes 1;
+    my ($r) = unpack 'C', $b;
+    return $r;
+}
+
+sub randvalue ($$) {
+    my ($min,$maxplus1) = @_;
+    my $b = randbyteval;
+    return floor(($b/256.0) * ($maxplus1-$min)) + $min;
+}
+
+for (;;) {
+    my $lenbits = randvalue 0,14;
+    my $len= (randbyteval << 8) | randbyteval;
+    $len &= (1 << $lenbits)-1;
+    my $data = randbytes $len;
+    if (randbyteval >= 0x80) {
+       $data =~ s{[\xc0\xdb]}{
+            $& eq "\xc0" ? "\xcb\xdc" :
+            $& eq "\xdb" ? "\xcb\xdd" :
+            die
+        }ge;
+    }
+    print "\xc0";
+    print $data;
+    STDOUT->flush;
+}