[Tutor] Safely buffering user input

Miles Stevenson miles at mstevenson.org
Thu Jan 27 19:08:05 CET 2005


Newbie question.

I'm trying to practice safe coding techniques. I just want to make sure that a 
user can't supply a massive argument to my script and cause trouble. I'm just 
trying only accept about 256 bytes:

buffer(sys.argv[1], 0, 256)
searchpath = sys.argv[1]

The script runs successfully, but when I give the script much more than 256 
characters, it doesn't seem to chop it off. It still holds the entire long 
string and prints the whole thing back out again when I do a:

print searchpath

I assume the size arguments to buffer() are in bytes? Am I not using this 
correctly? Thanks in advance.

-- 
Miles Stevenson
miles at mstevenson.org
PGP FP: 035F 7D40 44A9 28FA 7453 BDF4 329F 889D 767D 2F63
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20050127/f75a1d92/attachment.pgp


More information about the Tutor mailing list