summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2015-02-02 17:40:25 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2015-02-02 17:40:25 +0000
commit4b8b16b4be4e66511b85e52727b15d272f0994cc (patch)
treec27cc85683ca20234793b270fdf88d033bfeade8
parentd377a9827043b19c64298b0242402240a4456408 (diff)
Test that long syslog messages are truncated correctly.
-rw-r--r--regress/usr.sbin/syslogd/Client.pm33
-rw-r--r--regress/usr.sbin/syslogd/args-length-tcp.pl39
-rw-r--r--regress/usr.sbin/syslogd/args-length-tls.pl39
-rw-r--r--regress/usr.sbin/syslogd/args-length-udp.pl45
-rw-r--r--regress/usr.sbin/syslogd/args-length-unix.pl36
-rw-r--r--regress/usr.sbin/syslogd/args-length-vis.pl46
-rw-r--r--regress/usr.sbin/syslogd/args-memory-overflow-flags.pl2
-rw-r--r--regress/usr.sbin/syslogd/args-memory-overflow.pl2
-rw-r--r--regress/usr.sbin/syslogd/args-sighup-tcp.pl1
-rw-r--r--regress/usr.sbin/syslogd/args-sighup-tls.pl1
-rw-r--r--regress/usr.sbin/syslogd/funcs.pl47
11 files changed, 275 insertions, 16 deletions
diff --git a/regress/usr.sbin/syslogd/Client.pm b/regress/usr.sbin/syslogd/Client.pm
index 7605360c963..47544606d9e 100644
--- a/regress/usr.sbin/syslogd/Client.pm
+++ b/regress/usr.sbin/syslogd/Client.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: Client.pm,v 1.2 2014/08/25 17:55:27 bluhm Exp $
+# $OpenBSD: Client.pm,v 1.3 2015/02/02 17:40:24 bluhm Exp $
# Copyright (c) 2010-2014 Alexander Bluhm <bluhm@openbsd.org>
#
@@ -30,6 +30,7 @@ sub new {
$args{logfile} ||= "client.log";
$args{up} ||= "Openlog";
my $self = Proc::new($class, %args);
+ $self->{connectproto} ||= "udp";
return $self;
}
@@ -37,16 +38,26 @@ sub child {
my $self = shift;
if (defined($self->{connectdomain})) {
- my $cs = IO::Socket::INET6->new(
- Proto => "udp",
- Domain => $self->{connectdomain},
- PeerAddr => $self->{connectaddr},
- PeerPort => $self->{connectport},
- ) or die ref($self), " socket connect failed: $!";
- print STDERR "connect sock: ",$cs->sockhost()," ",
- $cs->sockport(),"\n";
- print STDERR "connect peer: ",$cs->peerhost()," ",
- $cs->peerport(),"\n";
+ my $cs;
+ if ($self->{connectdomain} == AF_UNIX) {
+ $cs = IO::Socket::UNIX->new(
+ Type => SOCK_DGRAM,
+ Peer => $self->{connectpath} || "/dev/log",
+ ) or die ref($self), " socket unix failed: $!";
+ $cs->setsockopt(SOL_SOCKET, SO_SNDBUF, 10000)
+ or die ref($self), " setsockopt failed: $!";
+ } else {
+ $cs = IO::Socket::INET6->new(
+ Proto => $self->{connectproto},
+ Domain => $self->{connectdomain},
+ PeerAddr => $self->{connectaddr},
+ PeerPort => $self->{connectport},
+ ) or die ref($self), " socket connect failed: $!";
+ print STDERR "connect sock: ",$cs->sockhost()," ",
+ $cs->sockport(),"\n";
+ print STDERR "connect peer: ",$cs->peerhost()," ",
+ $cs->peerport(),"\n";
+ }
*STDIN = *STDOUT = $self->{cs} = $cs;
}
diff --git a/regress/usr.sbin/syslogd/args-length-tcp.pl b/regress/usr.sbin/syslogd/args-length-tcp.pl
new file mode 100644
index 00000000000..b935805678d
--- /dev/null
+++ b/regress/usr.sbin/syslogd/args-length-tcp.pl
@@ -0,0 +1,39 @@
+# The client writes long messages to UDP socket.
+# The syslogd writes it into a file and through a pipe.
+# The syslogd passes it via TCP to the loghost.
+# The server receives the message on its TCP socket.
+# Find the message in client, file, pipe, syslogd, server log.
+# Check that lines in server have 8192 bytes message length.
+
+use strict;
+use warnings;
+use Socket;
+
+my $msg = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+our %args = (
+ client => {
+ connect => { domain => AF_UNSPEC, addr => "localhost", port => 514 },
+ func => \&write_length,
+ lengths => [ 8190..8193,9000 ],
+ },
+ syslogd => {
+ loghost => '@tcp://localhost:$connectport',
+ options => ["-u"],
+ loggrep => {
+ $msg => 5,
+ }
+ },
+ server => {
+ listen => { domain => AF_UNSPEC, proto => "tcp", addr => "localhost" },
+ # >>> <13>Jan 31 00:10:11 0123456789ABC...567
+ loggrep => {
+ $msg => 5,
+ qr/^>>> .{19} .{8190}$/ => 1,
+ qr/^>>> .{19} .{8191}$/ => 1,
+ qr/^>>> .{19} .{8192}$/ => 3,
+ },
+ },
+);
+
+1;
diff --git a/regress/usr.sbin/syslogd/args-length-tls.pl b/regress/usr.sbin/syslogd/args-length-tls.pl
new file mode 100644
index 00000000000..04fd3ab19fc
--- /dev/null
+++ b/regress/usr.sbin/syslogd/args-length-tls.pl
@@ -0,0 +1,39 @@
+# The client writes long messages to UDP socket.
+# The syslogd writes it into a file and through a pipe.
+# The syslogd passes it via TLS to the loghost.
+# The server receives the message on its TLS socket.
+# Find the message in client, file, pipe, syslogd, server log.
+# Check that lines in server have 8192 bytes message length.
+
+use strict;
+use warnings;
+use Socket;
+
+my $msg = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+our %args = (
+ client => {
+ connect => { domain => AF_UNSPEC, addr => "localhost", port => 514 },
+ func => \&write_length,
+ lengths => [ 8190..8193,9000 ],
+ },
+ syslogd => {
+ loghost => '@tls://localhost:$connectport',
+ options => ["-u"],
+ loggrep => {
+ $msg => 5,
+ }
+ },
+ server => {
+ listen => { domain => AF_UNSPEC, proto => "tls", addr => "localhost" },
+ # >>> <13>Jan 31 00:10:11 0123456789ABC...567
+ loggrep => {
+ $msg => 5,
+ qr/^>>> .{19} .{8190}$/ => 1,
+ qr/^>>> .{19} .{8191}$/ => 1,
+ qr/^>>> .{19} .{8192}$/ => 3,
+ },
+ },
+);
+
+1;
diff --git a/regress/usr.sbin/syslogd/args-length-udp.pl b/regress/usr.sbin/syslogd/args-length-udp.pl
new file mode 100644
index 00000000000..c50af7df5dc
--- /dev/null
+++ b/regress/usr.sbin/syslogd/args-length-udp.pl
@@ -0,0 +1,45 @@
+# The client writes long messages to UDP socket.
+# The syslogd writes it into a file and through a pipe.
+# The syslogd passes it via UDP to the loghost.
+# The server receives the message on its UDP socket.
+# Find the message in client, file, pipe, syslogd, server log.
+# Check that lines in server have 1180 bytes line length.
+# Check that lines in file have 8192 bytes message length after the header.
+
+use strict;
+use warnings;
+use Socket;
+
+my $msg = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+our %args = (
+ client => {
+ connect => { domain => AF_UNSPEC, addr => "localhost", port => 514 },
+ func => \&write_length,
+ lengths => [ 8190..8193,9000 ],
+ },
+ syslogd => {
+ options => ["-u"],
+ loggrep => {
+ $msg => 5,
+ }
+ },
+ server => {
+ # >>> <13>Jan 31 00:10:11 0123456789ABC...lmn
+ loggrep => {
+ $msg => 5,
+ qr/^>>> .{1180}$/ => 5,
+ },
+ },
+ file => {
+ # Jan 31 00:12:39 localhost 0123456789ABC...567
+ loggrep => {
+ $msg => 5,
+ qr/^.{25} .{8190}$/ => 1,
+ qr/^.{25} .{8191}$/ => 1,
+ qr/^.{25} .{8192}$/ => 3,
+ },
+ },
+);
+
+1;
diff --git a/regress/usr.sbin/syslogd/args-length-unix.pl b/regress/usr.sbin/syslogd/args-length-unix.pl
new file mode 100644
index 00000000000..0933d6eff98
--- /dev/null
+++ b/regress/usr.sbin/syslogd/args-length-unix.pl
@@ -0,0 +1,36 @@
+# The client writes long messages to unix domain socket /dev/log.
+# The syslogd writes it into a file and through a pipe.
+# The syslogd passes it via UDP to the loghost.
+# The server receives the message on its UDP socket.
+# Find the message in client, file, pipe, syslogd, server log.
+# Check that lines in file have 8192 bytes message length after the header.
+
+use strict;
+use warnings;
+use Socket;
+
+my $msg = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+our %args = (
+ client => {
+ connect => { domain => AF_UNIX },
+ func => \&write_length,
+ lengths => [ 8190..8193,9000 ],
+ },
+ syslogd => {
+ loggrep => {
+ $msg => 5,
+ }
+ },
+ file => {
+ # Feb 2 00:43:36 hostname 0123456789ABC...567
+ loggrep => {
+ $msg => 5,
+ qr/^.{15} \S{1,256} .{8190}$/ => 1,
+ qr/^.{15} \S{1,256} .{8191}$/ => 1,
+ qr/^.{15} \S{1,256} .{8192}$/ => 3,
+ },
+ },
+);
+
+1;
diff --git a/regress/usr.sbin/syslogd/args-length-vis.pl b/regress/usr.sbin/syslogd/args-length-vis.pl
new file mode 100644
index 00000000000..158ecbce9e3
--- /dev/null
+++ b/regress/usr.sbin/syslogd/args-length-vis.pl
@@ -0,0 +1,46 @@
+# The client writes long messages to UDP socket.
+# The syslogd writes it into a file and through a pipe.
+# The syslogd passes it via UDP to the loghost.
+# The server receives the message on its UDP socket.
+# Find the message in client, file, pipe, syslogd log.
+# Check that lines with visual encoding at the end are truncated.
+
+use strict;
+use warnings;
+use Socket;
+
+my $msg = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+our %args = (
+ client => {
+ connect => { domain => AF_UNSPEC, addr => "localhost", port => 514 },
+ func => \&write_length,
+ lengths => [ 8186..8195,9000 ],
+ tail => "foo\200",
+ },
+ syslogd => {
+ options => ["-u"],
+ loggrep => {
+ $msg => 11,
+ }
+ },
+ file => {
+ # Jan 31 00:12:39 localhost 0123456789ABC...567
+ loggrep => {
+ $msg => 11,
+ qr/^.{25} .{8182}foo\\M\^\@$/ => 1,
+ qr/^.{25} .{8183}foo\\M\^\@$/ => 1,
+ qr/^.{25} .{8184}foo\\M\^\@$/ => 1,
+ qr/^.{25} .{8185}foo\\M\^\@$/ => 1,
+ qr/^.{25} .{8186}foo\\M\^$/ => 1,
+ qr/^.{25} .{8187}foo\\M$/ => 1,
+ qr/^.{25} .{8188}foo\\$/ => 1,
+ qr/^.{25} .{8189}foo$/ => 1,
+ qr/^.{25} .{8190}fo$/ => 1,
+ qr/^.{25} .{8191}f$/ => 1,
+ qr/^.{25} .{8192}$/ => 8,
+ },
+ },
+);
+
+1;
diff --git a/regress/usr.sbin/syslogd/args-memory-overflow-flags.pl b/regress/usr.sbin/syslogd/args-memory-overflow-flags.pl
index 1a4eb9b4b5a..bc6ed02852d 100644
--- a/regress/usr.sbin/syslogd/args-memory-overflow-flags.pl
+++ b/regress/usr.sbin/syslogd/args-memory-overflow-flags.pl
@@ -13,7 +13,7 @@ our %args = (
client => {
func => sub {
my $self = shift;
- foreach (1..4) {
+ foreach (1..40) {
write_message($self, $_ x 1024);
}
write_log($self);
diff --git a/regress/usr.sbin/syslogd/args-memory-overflow.pl b/regress/usr.sbin/syslogd/args-memory-overflow.pl
index 0c5a984c81b..f3bc6a9faaa 100644
--- a/regress/usr.sbin/syslogd/args-memory-overflow.pl
+++ b/regress/usr.sbin/syslogd/args-memory-overflow.pl
@@ -12,7 +12,7 @@ our %args = (
client => {
func => sub {
my $self = shift;
- foreach (1..4) {
+ foreach (1..40) {
write_message($self, $_ x 1024);
}
write_log($self);
diff --git a/regress/usr.sbin/syslogd/args-sighup-tcp.pl b/regress/usr.sbin/syslogd/args-sighup-tcp.pl
index 0a31dbd3fcf..8e5cff53a13 100644
--- a/regress/usr.sbin/syslogd/args-sighup-tcp.pl
+++ b/regress/usr.sbin/syslogd/args-sighup-tcp.pl
@@ -7,6 +7,7 @@
use strict;
use warnings;
+use Socket;
our %args = (
client => {
diff --git a/regress/usr.sbin/syslogd/args-sighup-tls.pl b/regress/usr.sbin/syslogd/args-sighup-tls.pl
index 844e6d3a9e9..0093ef28e9c 100644
--- a/regress/usr.sbin/syslogd/args-sighup-tls.pl
+++ b/regress/usr.sbin/syslogd/args-sighup-tls.pl
@@ -7,6 +7,7 @@
use strict;
use warnings;
+use Socket;
our %args = (
client => {
diff --git a/regress/usr.sbin/syslogd/funcs.pl b/regress/usr.sbin/syslogd/funcs.pl
index 397a580db55..ff7144a246b 100644
--- a/regress/usr.sbin/syslogd/funcs.pl
+++ b/regress/usr.sbin/syslogd/funcs.pl
@@ -1,4 +1,4 @@
-# $OpenBSD: funcs.pl,v 1.12 2015/01/22 00:34:32 bluhm Exp $
+# $OpenBSD: funcs.pl,v 1.13 2015/02/02 17:40:24 bluhm Exp $
# Copyright (c) 2010-2015 Alexander Bluhm <bluhm@openbsd.org>
#
@@ -16,6 +16,8 @@
use strict;
use warnings;
+no warnings 'experimental::smartmatch';
+use feature 'switch';
use Errno;
use List::Util qw(first);
use Socket;
@@ -74,8 +76,18 @@ sub write_message {
my $self = shift;
if (defined($self->{connectdomain})) {
- print @_;
- print STDERR @_, "\n";
+ if ($self->{connectproto} eq "udp") {
+ # writing udp packets works only with syswrite()
+ my $msg = join("", @_);
+ defined(my $n = syswrite(STDOUT, $msg))
+ or die ref($self), " write log line failed: $!";
+ $n == length($msg)
+ or die ref($self), " short UDP write";
+ print STDERR $msg, "\n";
+ } else {
+ print @_;
+ print STDERR @_, "\n";
+ }
} else {
syslog(LOG_INFO, @_);
}
@@ -89,6 +101,35 @@ sub write_shutdown {
syslog(LOG_NOTICE, $downlog);
}
+sub write_char {
+ my $self = shift;
+ my @lenghts = @_ || @{$self->{lengths}};
+
+ foreach my $len (@lenghts) {
+ my $tail = $self->{tail} // "";
+ substr($tail, 0, length($tail) - $len, "")
+ if length($tail) && length($tail) > $len;
+ my $msg = "";
+ my $char = '0';
+ for (my $i = 0; $i < $len - length($tail); $i++) {
+ $msg .= $char;
+ given ($char) {
+ when(/9/) { $char = 'A' }
+ when(/Z/) { $char = 'a' }
+ when(/z/) { $char = '0' }
+ default { $char++ }
+ }
+ }
+ $msg .= $tail if length($tail);
+ write_message($self, $msg);
+ }
+}
+
+sub write_length {
+ write_char(@_);
+ write_log(@_);
+}
+
sub write_unix {
my $self = shift;
my $path = shift || "/dev/log";