Re: Check valid filename before copy
From: Ben Morrow (usenet_at_morrow.me.uk)
Date: 02/25/04
- Next message: Tore Aursand: "Re: finding common words"
- Previous message: Noel Sant: "Closing and re-opening redirected STDOUT"
- In reply to: Gary Mayor: "Check valid filename before copy"
- Next in thread: Gary Mayor: "Re: Check valid filename before copy"
- Reply: Gary Mayor: "Re: Check valid filename before copy"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 25 Feb 2004 15:49:10 +0000 (UTC)
Gary Mayor <gary@abertron.co.uk> wrote:
> I'm getting a filename from a user then copying a file to a new file
> with the new filename specified by the user. So the script is like this
>
> $file = param("file");
>
> system("cp $from $file");
Don't use system, use File::Copy.
> I need to check the $file string for any invalid characters such as ../
> @ |. I can do a regex expression to check them but I was hopeing someone
> had already done the expressions what would be all the characters I
> would need to check for security reasons?
>
> Sample Regex
>
> $file=~/\.|\..|\/|\@/)
>
> Is there a better way
>
> Ideas Please?
Don't look for invalid characters, look for valid ones.
die unless $file =~ /^[\w.-+]+$/;
Ben
--
We do not stop playing because we grow old;
we grow old because we stop playing.
ben@morrow.me.uk
- Next message: Tore Aursand: "Re: finding common words"
- Previous message: Noel Sant: "Closing and re-opening redirected STDOUT"
- In reply to: Gary Mayor: "Check valid filename before copy"
- Next in thread: Gary Mayor: "Re: Check valid filename before copy"
- Reply: Gary Mayor: "Re: Check valid filename before copy"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|