access() Security Hole

后端 未结 3 1786
暖寄归人
暖寄归人 2020-12-21 06:41

I\'ve been doing some shell writing and came across a recommendation for access() to check whether a file exists, can be read, etc. Seems super easy to implement and faster

3条回答
  •  时光取名叫无心
    2020-12-21 07:17

    The pattern seems to be calling access() or stat() to determine whether you can open a file, and then opening it if you have permission.

    Instead, it's usually better just to go ahead and try to open it, and then check whether the attempt succeeded (and if not, why). This avoids the time interval between the check and the attempt to open the file.

提交回复
热议问题