"Fossies" - the Fresh Open Source Software Archive 
Member "memcached-1.6.15/t/malicious-commands.t" (16 Jul 2020, 820 Bytes) of package /linux/www/memcached-1.6.15.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 #!/usr/bin/perl
2
3 # These command strings are always expected to be malicious and as such we
4 # should just hang up on them.
5
6 use strict;
7 use Test::More tests => 3;
8 use FindBin qw($Bin);
9 use lib "$Bin/lib";
10 use MemcachedTest;
11
12 my @strs = (
13 "GET / HTTP/1.0",
14 "PUT /asdf/asd/fasdfasdf/sadf HTTP/1.1",
15 "DELETE HTTP/1.1"
16 );
17
18 for my $str (@strs) {
19 my $server = new_memcached();
20 my $sock = $server->sock;
21
22 print $sock "$str\r\n";
23
24 # Five seconds ought to be enough to get hung up on.
25 my $oldalarmt = alarm(5);
26
27 # Verify we can't read anything.
28 my $bytesread = -1;
29 eval {
30 local $SIG{'ALRM'} = sub { die "timeout" };
31 my $data = "";
32 $bytesread = sysread($sock, $data, 24),
33 };
34 is($bytesread, 0, $str);
35
36 # Restore signal stuff.
37 alarm($oldalarmt);
38 }