Hello World

Chris Warrick kwpolska at gmail.com
Mon Dec 22 11:03:59 EST 2014


On Mon, Dec 22, 2014 at 4:36 PM, Jussi Piitulainen
<jpiitula at ling.helsinki.fi> wrote:
> Steven D'Aprano writes:
>
>> Don't try this at home!
>>
>> # download_naked_pictures_of_jennifer_lawrence.py
>> import os
>> os.system("rm ――rf /")
>
> Not sure what that character is (those characters are) but it's not
> (they aren't) the hyphen that rm expects in its options, so:
>
>   >>> os.system("rm ――rf /")
>   rm: cannot remove `――rf': No such file or directory
>   rm: cannot remove `/': Is a directory
>   256

Let‘s ask Python: (polyglot 2.6+/3.3+ code!)

from __future__ import print_function
import unicodedata
command = u"rm ――rf /"
for i in command:
    print(hex(ord(i)), unicodedata.name(i))

0x72 LATIN SMALL LETTER R
0x6d LATIN SMALL LETTER M
0x20 SPACE
0x2015 HORIZONTAL BAR
0x2015 HORIZONTAL BAR
0x72 LATIN SMALL LETTER R
0x66 LATIN SMALL LETTER F
0x20 SPACE
0x2f SOLIDUS

There’s your answer: it’s U+2015 HORIZONTAL BAR, twice.  And `rm`
wants U+002D HYPHEN-MINUS instead.

Moreover, it wants only one HYPHEN-MINUS and not two:

Linux:
$ rm --rf /
rm: unrecognized option '--rf'
Try 'rm --help' for more information.

BSD:
$ rm --rf /
rm: illegal option -- -
usage: rm [-f | -i] [-dIPRrvWx] file ...
       unlink file

That’s two-step “protection”.

(This e-mail brought to you by Unicode.)

-- 
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16



More information about the Python-list mailing list