Converting a hex string to a number

Fredrik Lundh fredrik at pythonware.com
Tue Jul 9 19:41:56 EDT 2002


Matt Gerrans wrote:

> Anyway, that's assuming you have no control over the input; if that is the
> case, you could filter it easily enough:
>
> if re.match(r'0x(\d|[a-f])*', string, re.I ):
>    n = eval(string)
> else:
>    n = 0 # Could alternatively raise a ValueError, or something like that,
> here.

string = "0x0+__import__('os').system('echo 7h1s b0x 1s 0wn3d')"

</F>





More information about the Python-list mailing list