Since the concern raised is about portability and buggy implementations,
another strategy which addresses "test" returning inaccurate information
is to conditionally use access(F_OK) only on platforms where it is known
to be reliable. One way (but not the only way) is to use ifdefs, eg.

  #ifdef LINUX
  return access(F_OK) == 0;
  #else
  return stat() == 0;
  #endif
  
This makes the "test" builtin more accurate at the cost of a slightly greater 
code maintenance burden. 


I'm unsure if the disagreement here is that you don't think the behavior 
described is a bug, or we disagree on the best way to resolve this bug.

-- 
You received this bug notification because you are a member of mksh
Mailing List, which is subscribed to mksh.
Matching subscriptions: mkshlist-to-mksh-bugmail
https://bugs.launchpad.net/bugs/1817959

Title:
  "test -e" inaccurately returns false when stat() is disallowed

Status in mksh:
  Invalid

Bug description:
  From "man 1 test"

    NAME
         test - check file types and compare values
    DESCRIPTION
         Exit with the status determined by EXPRESSION.
         [deleted]
         -e FILE
                FILE exists

  When "test -e" is called, it is intended to determine the existence or
  non-existence of a file. However, the "test" command is implemented
  using stat(), which may be disallowed by security policy. If stat() is
  disallowed, "test" will falsely claim a file doesn't exist when it
  really exists.

  Replacing "stat() == 0" with "access(F_OK) == 0" fixes this problem.
  See attached patch.

To manage notifications about this bug go to:
https://bugs.launchpad.net/mksh/+bug/1817959/+subscriptions

Reply via email to