Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8701273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:21:29+00:00 2026-06-13T02:21:29+00:00

The code ‘if(-e filename)’ tests for existence of a file with name filename in

  • 0

The code ‘if(-e “filename”)’ tests for existence of a file with name filename in the directory the script containing that code is executed in.

What is doing the name check? Perl? The OS? Bash on POSIX-os?

Would ‘if(-e “cat string”)’ execute the cat command on Linux?

I want to know in order to be able to avert undesired file access like “../file” would access a file in the parent directory.

To share my check code:

if($folder =~ m/$([\\]?\.[\\]?\.|[\\]?\\|[\\]?\/|[\\]?\?|[\\]?*|[\\]?:|[\\]?\||[\\]?\"|[\\]?\<|[\\]?\>)^|$([\\]?\.[\\]?\.|[\\]?\\|[\\]?\/|[\\]?\?|[\\]?*|[\\]?:|[\\]?\||[\\]?\"|[\\]?\<|[\\]?\>)\/|\/([\\]?\.[\\]?\.|[\\]?\\|[\\]?\/|[\\]?\?|[\\]?*|[\\]?:|[\\]?\||[\\]?\"|[\\]?\<|[\\]?\>)\/|\/([\\]?\.[\\]?\.|[\\]?\\|[\\]?\/|[\\]?\?|[\\]?*|[\\]?:|[\\]?\||[\\]?\"|[\\]?\<|[\\]?\>)^|\$'[^']*'/)
{
    #error
}

Updated regular expression:

if($folder =~ m/(\/|\\)|$([\\]?\.[\\]?\.^|$[\\]?(\*|\?)^|\$'[^']*'/)
{
    #error
}

Explanation: $folder shall be a pure filename already. If it contains Windows or POSIX path separators or is (any escaped) parent directory back link or is (any escaped) wild card (as that matches the first matching file and returns true on Mac OS X at least) or contains a C ANSI escape sequence anywhere, signal error. Anything else, even if not legal or if shady, should simply return a “file not exists” and thus may be supplied to an ‘if(-e $folder)’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:21:30+00:00Added an answer on June 13, 2026 at 2:21 am

    The operating system does. Perl’s call to -e (as well as others like -s) are implemented by calling the C library function stat.

    There is no shell involed, and therefore "cat some_file" will not be executed. Instead the OS looks for a file called “cat some_file”.

    stat can, of course, be called with relative path names. If you don’t want that then strip away everything but the file name + extension. There are Perl modules for this kind of thing.

    I don’t want to debug/look into your proposed regular expression because it is, quite honestly, completey unreadable and unmaintainable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code: <?php //initializing script, do not modify session_start(); define('IN_SCRIPT', true); //so that global.php cannot
Code to create new form instance of a closed form using form name I
code: <script src=http://www.openlayers.org/api/OpenLayers.js></script> <script type=text/javascript> map = new OpenLayers.Map(open_map); map.addLayer(new OpenLayers.Layer.OSM()); var lonLat =
Code for webpage such that if anyone closes it, then next time when he
Code Currently my code looks like that. $stmt = $this->db->prepare(SELECT m.id, m.from_id, m.to_id, m.subject,
I am doing a simple coin flipping experiment for class that involves flipping a
Code (Note that the result will not display properly without the images referenced) I'm
Code: <html xmlns=http://www.w3.org/1999/xhtml> <head> <title>Unusual Array Lengths!</title> <script type=text/javascript> var arrayList = new Array();
Code that is untestable really annoys me. The following things make oo-code untestable: global
(code examples are python) Lets assume we have a list of percentages that add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.