Skip to content
Snippets Groups Projects
Commit c77b4ebd authored by Gerhard Gonter's avatar Gerhard Gonter :speech_balloon:
Browse files

do not use substr out of bounds

parent 54d03605
No related branches found
No related tags found
No related merge requests found
...@@ -20,35 +20,35 @@ sub hexdump ...@@ -20,35 +20,35 @@ sub hexdump
my ($i, $c, $v); my ($i, $c, $v);
my $run= 1; my $run= 1;
my $dl= length ($data);
DATA: while ($run) DATA: while ($run)
{ {
my $char= ''; my $char= '';
my $hex= ''; my $hex= '';
my $offx= sprintf ('%08X', $off); my $offx= sprintf ('%08X', $off);
for ($i= 0; $i < 16; $i++) BYTE: for ($i= 0; $i < 16; $i++)
{ {
$c= substr ($data, $off+$i, 1); $hex .= ' ' if ($i == 8);
if ($i == 8) if ($off+$i < $dl)
{ {
$hex .= ' '; $c= substr ($data, $off+$i, 1);
}
if ($c ne '') if (defined ($c) && $c ne '')
{ {
$v= unpack ('C', $c); $v= unpack ('C', $c);
$c= '.' if ($v < 0x20 || $v >= 0x7F); $c= '.' if ($v < 0x20 || $v >= 0x7F);
$char .= $c; $char .= $c;
$hex .= sprintf (' %02X', $v); $hex .= sprintf (' %02X', $v);
} next BYTE;
else }
{
$char .= ' ';
$hex .= ' ';
$run= 0;
} }
$char .= ' ';
$hex .= ' ';
$run= 0;
} }
print FX "$offx $hex |$char|\n"; print FX "$offx $hex |$char|\n";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment