Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^5: hex numbers

by dave_the_m (Monsignor)
on Jan 14, 2021 at 19:06 UTC ( #11126926=note: print w/replies, xml ) Need Help??


in reply to Re^4: hex numbers
in thread hex numbers

And of course code which assumes that the string can only ever contain hex digits is an exploit waiting to happen.

Dave.

Replies are listed 'Best First'.
Re^6: hex numbers
by jcb (Parson) on Jan 15, 2021 at 02:34 UTC

    That is what regular expressions are for:

    local $_ = <STDIN>; chomp; my $hexnum = undef; $hexnum = eval "0x$1" if (m/^(?:0[xX])?([[:xdigit:]]+)$/); die "bad input" unless defined $hexnum;

    Do not assume that the input meets your constraints — verify that the input meets your constraints! :-)

Re^6: hex numbers
by shmem (Chancellor) on Jan 14, 2021 at 19:58 UTC
    And of course code which assumes that the string can only ever contain hex digits is an exploit waiting to happen.

    Code which doesn't assume the type of content of a variable but contains a string constant is only exploitable by editing the source file and munging the constant.

    See my answer to davido below.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11126926]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2021-04-21 12:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?