tmpnam warning saying it is dangerous

后端 未结 5 1076
醉话见心
醉话见心 2021-01-03 19:15

I get this warning saying that tmpnam is dangerous, but I would prefer to use it, since it can be used as is in Windows as well as Linux. I was wondering why it would be con

5条回答
  •  独厮守ぢ
    2021-01-03 19:52

    From the tmpnam(3) manpage:

    Although tmpnam() generates names that are difficult to guess, it is nevertheless possible that between the time that tmpnam() returns a pathname, and the time that the program opens it, another program might create that path‐ name using open(2), or create it as a symbolic link. This can lead to security holes. To avoid such possibili‐ ties, use the open(2) O_EXCL flag to open the pathname. Or better yet, use mkstemp(3) or tmpfile(3).

提交回复
热议问题