pipe() is better to be replaced by pipe2() with O_CLOEXEC flag to avoid file descriptor leakage.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Thanks for this!
I don't have great context on tidy, so I can't stamp this, but I do have a few drive-by nits for you.
clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp | ||
---|---|---|
22 ↗ | (On Diff #199692) | We probably don't want to commit commented out code |
27 ↗ | (On Diff #199692) | simplicity nit: can this be a std::string? |
clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h | ||
18 ↗ | (On Diff #199692) | nit: should probably update this comment |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe.cpp | ||
9 ↗ | (On Diff #199692) | (Do we have a CHECK-FIXES-NOT or CHECK-MESSAGES-NOT to apply to the things below? Or are the CHECKs here meant to be complete like clang's -verify?) |
clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe.rst | ||
---|---|---|
4 ↗ | (On Diff #199692) | Please make same length as name above. |
clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp | ||
---|---|---|
27 ↗ | (On Diff #199692) | replaceFunc takes a llvm::StringRef as the third parameter. StringRef is "expected to be used in situations where the character data resides in some other buffer, whose lifetime extends past that of the StringRef", which is true in this case, so I think it should be fine. |
clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h | ||
18 ↗ | (On Diff #199692) | Good catch! |
clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe.rst | ||
4 ↗ | (On Diff #199692) | Thanks for the comments. I have fixed them accordingly. |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe.cpp | ||
---|---|---|
9 ↗ | (On Diff #199692) | Based on Testing Checks https://clang.llvm.org/extra/clang-tidy/Contributing.html, CHECK-MASSAGES and CHECK-FIXES are sufficient for clang-tidy checks. I have double checked the tests for similar checks and they don't seem to have additional FileCheck invocations other than these two. |
clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp | ||
---|---|---|
27 ↗ | (On Diff #199692) | Both should be functionally equivalent in this code. My point was that it's not common to rely on temporary lifetime extension when writing the non-const& type would be equivalent (barring maybe cases with auto, but that's not applicable), and I don't see why we should break with that here. |
clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp | ||
---|---|---|
27 ↗ | (On Diff #199692) | Make sense. |
clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h | ||
---|---|---|
1 ↗ | (On Diff #199926) | Please extend to 80 characters. Same in source file. |
clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp | ||
---|---|---|
31 ↗ | (On Diff #202052) | the message doesn't seem to explain the reason, especially to the people who are not familiar with the pipe API, maybe prefer pipe2() to pipe() to avoid file descriptor leakage is clearer? Ah, it looks like you are following the existing CloexecCreatCheck check, no need to do it in this patch. |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe.cpp | ||
17 ↗ | (On Diff #202052) | nit: no need to do it explicitly, if a warning is shown unexpectedly, the test will fail. |
clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp | ||
---|---|---|
31 ↗ | (On Diff #202052) | "prefer pipe2() with O_CLOEXEC to avoid leaking file descriptors to child processes" No need to change in this patch if you're following an existing pattern, but please do update the message in all checks in a separate patch to explain things better. |
clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h | ||
18 ↗ | (On Diff #202052) | "Suggests to replace calls to pipe() with calls to pipe2()." |
clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe.rst | ||
6 ↗ | (On Diff #202052) | WDYT about this rewrite? """ The check also adds the O_CLOEXEC flag that marks the file descriptor to be closed in child processes. Without this flag a sensitive file descriptor can be leaked to a child process, potentially into a lower-privileged SELinux domain. |
16 ↗ | (On Diff #202052) | "Suggested replacement" Also use a separate code block for the replacement. |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe.cpp | ||
---|---|---|
17 ↗ | (On Diff #202052) | I somehow never realized this (and there seem to be several places that also don't realize it). Thanks for letting us know. |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe.cpp | ||
---|---|---|
5 ↗ | (On Diff #202052) | Please give the tests informative names instead of f, g etc. |
Will submit once gribozavr indicates that they're happy with the new test names. Thanks again for working on this!