jepri has asked for the wisdom of the Perl Monks concerning the following question:
Finally after many hours debugging I discover that it's my fault. For some reason, my while loop was exiting before it reaches the end of the string. It turns out that there is a magic character in the stream that causes Perl to end the string too soon. But here's the confusing bit - *only some commands are vulnerable*. I can print out the entire string. But I can't substr it. Then when I try to print it again, it is foreshortened.
The evil character appears near (before, I think) the character '0' - that's the number 0. Naturally I guess unknown character is an end-of-string character for perl, but it's not a chr(0) - those come through fine.
while (!(recv $connection,$z,1000,0)){}; #The following line prints the correct number of packets #fetched print "\nLength fetched: ",length($z)," string ",$z if length($z); my $g=0; #$z=quotemeta $z; #This while exits *before* it has finished the string while (my $a=substr $z,$g,1) { $g++; #Process characters in this here
Does anyone know what's going on? I'd appreciate any help or pointers to info that you know of. I read part of the perguts manpage but I couldn't figure anything useful from it.
____________________
Jeremy
I didn't believe in evil until I dated it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bad Char in string
by jeroenes (Priest) on Apr 19, 2001 at 14:19 UTC | |
by jepri (Parson) on Apr 19, 2001 at 15:13 UTC | |
|
Re: Bad Char in string
by mr.nick (Chaplain) on Apr 19, 2001 at 16:53 UTC | |
|
Errata
by jepri (Parson) on Apr 19, 2001 at 13:34 UTC | |
|
Re: Bad Char in string
by physi (Friar) on Apr 19, 2001 at 13:55 UTC | |
by jepri (Parson) on Apr 19, 2001 at 14:53 UTC |