From: minima Date: Sun, 30 Jul 2000 22:08:02 +0000 (+0000) Subject: fiddle with 8 bit characters, start to check everything more rigourously X-Git-Tag: R_1_43~13 X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=2c3a20bdcef84e620b0c3c2d306a71ebe17956b0;p=spider.git fiddle with 8 bit characters, start to check everything more rigourously --- diff --git a/Changes b/Changes index f922a1e8..968fc9ef 100644 --- a/Changes +++ b/Changes @@ -8,6 +8,8 @@ 7. stopped a few more things being done by rcmd (eg send, talk, ann, dx) 8. tidied up the talking a bit more. 9. Increase default hop counts all round. +10. Adjust hex encoding so that 8 bit characters should now go thru +11. check more of the essential protocol fields for 8 bit characters. 29Jul00======================================================================= 1. added forward/latlong which will forward ALL the users that have a latitude and longitude set on them to one or more locally connected nodes - with a hop diff --git a/perl/DXProt.pm b/perl/DXProt.pm index 90506ed4..310416e8 100644 --- a/perl/DXProt.pm +++ b/perl/DXProt.pm @@ -158,8 +158,8 @@ sub normal return unless $pcno; return if $pcno < 10 || $pcno > 99; - # dump bad protocol messages unless it is a PC29 - if ($line =~ /\%[0-9A-F][0-9A-F]/o && $pcno != 29) { + # dump bad protocol messages + if ($line =~ /\%[01][0-9A-F]/) { dbg('chan', "CORRUPT protocol message - dumped"); return; } @@ -175,16 +175,24 @@ sub normal SWITCH: { if ($pcno == 10) { # incoming talk + unless (is_callsign($field[1]) && is_callsign($field[2]) && is_callsign($field[6])) { + dbg('chan', "Corrupt talk, rejected"); + return; + } # is it for me or one of mine? - my $call = ($field[5] gt ' ') ? $field[5] : $field[2]; - if ($call eq $main::mycall || grep $_ eq $call, DXChannel::get_all_user_calls()) { - - # yes, it is - my $text = unpad($field[3]); - Log('talk', $call, $field[1], $field[6], $text); - $call = $main::myalias if $call eq $main::mycall; - my $ref = DXChannel->get($call); - $ref->send("$call de $field[1]: $text") if $ref && $ref->{talk}; + my ($to, $via, $call, $dxchan); + if ($field[5] gt ' ') { + $call = $via = $field[2]; + $to = $field[5]; + unless (is_callsign($to)) { + dbg('chan', "Corrupt talk, rejected"); + return; + } + } else { + $call = $to = $field[2]; + } + if ($dxchan = DXChannel->get($call)) { + $dxchan->talk($field[1], $to, $via, $field[3]); } else { $self->route($field[2], $line); # relay it on its way } @@ -193,6 +201,16 @@ sub normal if ($pcno == 11 || $pcno == 26) { # dx spot + # are any of the callsign fields invalid? + unless ($field[2] !~ m/[^A-Z0-9\-\/]/ && is_callsign($field[6]) && is_callsign($field[7])) { + dbg('chan', "Spot contains lower case callsigns or blanks, rejected"); + return; + } + if ($field[1] =~ m/[^0-9\.]/) { + dbg('chan', "Spot frequency not numeric, rejected"); + return; + } + # route 'foreign' pc26s if ($pcno == 26) { if ($field[7] ne $main::mycall) { @@ -220,16 +238,6 @@ sub normal dbg('chan', "Bad DX spot, ignored"); return; } - - # are any of the callsign fields invalid? - if ($field[2] =~ m/[^A-Z0-9\-\/]/ || $field[6] =~ m/[^A-Z0-9\-]/ || $field[7] =~ m/[^A-Z0-9\-]/) { - dbg('chan', "Spot contains lower case callsigns or blanks, rejected"); - return; - } - if ($field[1] =~ m/[^0-9\.]/) { - dbg('chan', "Spot frequency not numeric, rejected"); - return; - } # do some de-duping $field[5] =~ s/^\s+//; # take any leading blanks off @@ -307,6 +315,11 @@ sub normal } if ($pcno == 12) { # announces + unless (is_callsign($field[1]) && is_callsign($field[2]) && is_callsign($field[5])) { + dbg('chan', "Corrupt announce, rejected"); + return; + } + # announce duplicate checking $field[3] =~ s/^\s+//; # remove leading blanks if (AnnTalk::dup($field[1], $field[2], $field[3])) { @@ -1413,6 +1426,12 @@ sub disconnect $self->SUPER::disconnect; } +# check that a field only has callsign characters in it +sub is_callsign +{ + return $_[0] !~ /[^A-Z0-9\-]/ +} + # # send a talk message to this thingy # diff --git a/perl/Msg.pm b/perl/Msg.pm index f5704a81..0af67911 100644 --- a/perl/Msg.pm +++ b/perl/Msg.pm @@ -237,7 +237,7 @@ FINISH: while (@lines){ $msg = shift @lines; - $msg =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; + $msg =~ s/%([2-9A-F][0-9A-F])/chr(hex($1))/eg; &{$conn->{rcvd_notification_proc}}($conn, $msg, $!); $! = 0; } diff --git a/src/client.c b/src/client.c index 0b41241e..c330536b 100644 --- a/src/client.c +++ b/src/client.c @@ -448,12 +448,10 @@ int fcb_handler(sel_t *sp, int in, int out, int err) case 1: mp->state = 2; - if (ch >= '0' && ch <= '9') + if (ch >= '2' && ch <= '9') c = (ch - '0') << 4; else if (ch >= 'A' && ch <= 'F') c = (ch - 'A' + 10) << 4; - else if (ch >= 'a' && ch <= 'a') - c = (ch - 'a' + 10) << 4; else { dbg(DMSG, "Illegal hex char (%c) received in state %d", ch, mp->state); mp->inp = mp->data; @@ -466,8 +464,6 @@ int fcb_handler(sel_t *sp, int in, int out, int err) *mp->inp++ = c | (ch - '0'); else if (ch >= 'A' && ch <= 'F') *mp->inp++ = c | (ch - 'A' + 10); - else if (ch >= 'a' && ch <= 'a') - *mp->inp++ = c | (ch - 'a' + 10); else { dbg(DMSG, "Illegal hex char (%c) received in state %d", ch, mp->state); mp->inp = mp->data;