Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warning: the use of mktemp' is dangerous, better use mkstemp' or `mkdtemp' #5158

Open
toffaletti opened this issue Jan 19, 2025 · 3 comments

Comments

@toffaletti
Copy link
Contributor

Using swift:latest docker image I see this warning still. However, it seems like it should have been addressed back in Dec of 2020: #2927

I'm using the docker image created by this Dockerfile: https://github.com/swiftlang/swift-docker/blob/01bc0e265e8dca6381d801b76762ada6836afb69/6.0/ubuntu/24.04/Dockerfile

root@56a5c7b80758:/code# swift --version
Swift version 6.0.3 (swift-6.0.3-RELEASE)
Target: x86_64-unknown-linux-gnu
root@56a5c7b80758:/code# strings /usr/lib/swift_static/linux/libFoundationEssentials.a | grep mktemp
mktemp
root@56a5c7b80758:/code# strings /usr/lib/swift_static/linux/libFoundationEssentials.a | grep mkstemp
root@56a5c7b80758:/code#
root@56a5c7b80758:/code# strings /usr/lib/swift/linux/libFoundationEssentials.so | grep mktemp
mktemp
mktemp
root@56a5c7b80758:/code# strings /usr/lib/swift/linux/libFoundationEssentials.so | grep mkstemp
root@56a5c7b80758:/code#
swift build --static-swift-stdlib
Building for debugging...
/usr/lib/swift_static/linux/libFoundationEssentials.a(Data+Writing.swift.o):_ThreadLocal.swift.o:function $s20FoundationEssentials19createTemporaryFile33_FC9EC52B075D2ACCFF86F1C9F84293BELL2at6inPath6prefix7optionss5Int32V_SStSS_AA0Q5OrURLOSSAA4DataV14WritingOptionsVtKFTf4nnnd_n:(.text+0x2122): warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'
/usr/lib/swift_static/linux/libFoundationEssentials.a(Data+Writing.swift.o):_ThreadLocal.swift.o:function $s20FoundationEssentials19createTemporaryFile33_FC9EC52B075D2ACCFF86F1C9F84293BELL2at6inPath6prefix7optionss5Int32V_SStSS_AA0Q5OrURLOSSAA4DataV14WritingOptionsVtKFTf4nnnd_n:(.text+0x21b8): warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'
/usr/lib/swift_static/linux/libFoundationEssentials.a(Data+Writing.swift.o):_ThreadLocal.swift.o:function $s20FoundationEssentials19createTemporaryFile33_FC9EC52B075D2ACCFF86F1C9F84293BELL2at6inPath6prefix7optionss5Int32V_SStSS_AA0Q5OrURLOSSAA4DataV14WritingOptionsVtKFTf4nnnd_n:(.text+0x21f5): warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'
/usr/lib/swift_static/linux/libFoundationEssentials.a(Data+Writing.swift.o):_ThreadLocal.swift.o:function $s20FoundationEssentials19createTemporaryFile33_FC9EC52B075D2ACCFF86F1C9F84293BELL2at6inPath6prefix7optionss5Int32V_SStSS_AA0Q5OrURLOSSAA4DataV14WritingOptionsVtKFTf4nnnd_n:(.text+0x2286): warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'
/usr/lib/swift_static/linux/libFoundationEssentials.a(Data+Writing.swift.o):_ThreadLocal.swift.o:function $s20FoundationEssentials19createTemporaryFile33_FC9EC52B075D2ACCFF86F1C9F84293BELL2at6inPath6prefix7optionss5Int32V_SStSS_AA0Q5OrURLOSSAA4DataV14WritingOptionsVtKFTf4nnnd_n:(.text+0x22f1): warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'
@toffaletti
Copy link
Contributor Author

I verified the change is in the release/6.0 branch which seems to be where 6.0.3 is supposed to be tagged from:

let fd = mkstemp(buffer.baseAddress!)

@toffaletti
Copy link
Contributor Author

@parkera
Copy link
Contributor

parkera commented Jan 21, 2025

There is an explanation in the source of why this doesn't work for us:

        // The warning diligently tells us we shouldn't be using mktemp() because blindly opening the returned path opens us up to a TOCTOU race. However, in this case, we're being careful by doing O_CREAT|O_EXCL and repeating, just like the implementation of mkstemp.
        // Furthermore, we can't compatibly switch to mkstemp() until we have the ability to set fchmod correctly, which requires the ability to query the current umask, which we don't have. (22033100)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants