[PATCH 6/6] test-example: Provide a fuzzer for the slip decoder

Ian Jackson ijackson at chiark.greenend.org.uk
Mon Sep 22 16:45:13 BST 2014


Signed-off-by: Ian Jackson <ijackson at chiark.greenend.org.uk>
---
 test-example/outside-random.conf |   16 ++++++++++++++
 test-example/random-fake-userv   |   45 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)
 create mode 100644 test-example/outside-random.conf
 create mode 100755 test-example/random-fake-userv

diff --git a/test-example/outside-random.conf b/test-example/outside-random.conf
new file mode 100644
index 0000000..5c23920
--- /dev/null
+++ b/test-example/outside-random.conf
@@ -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
index 0000000..cccd22c
--- /dev/null
+++ b/test-example/random-fake-userv
@@ -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;
+}
-- 
1.7.10.4




More information about the sgo-software-discuss mailing list