-
Notifications
You must be signed in to change notification settings - Fork 165
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
Don't define strlcpy on musl libc #110
Conversation
Thanks for this ! |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved assuming this will make the Falco minimal build again. Anyway, I agree with @gnosek we shouldn't rely on MINIMAL_BUILD
for that. Let me know if we find a better solution.
LGTM label has been added. Git tree hash: 8b8b279f28c1fc4ea40e088de0336398c3e730e3
|
Here's the declaration of strlcpy in musl's string.h, from http://git.musl-libc.org/cgit/musl/tree/include/string.h#n81:
So musl declares it when either GNU_SOURCE or BSD_SOURCE are defined. musl also doesn't have its own declaration like __MUSL_SOURCE, see https://wiki.musl-libc.org/faq.html. So I'm not sure of any explicit define that we could use, other than something we could set when we set MINIMAL_BUILD, which is effectively this anyway. |
I would rather do: diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2b7544db..47c33719 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -69,3 +69,10 @@ if(CREATE_TEST_TARGETS AND NOT WIN32)
COMMAND ${CMAKE_MAKE_PROGRAM} run-unit-test-libsinsp
)
endif()
+
+include(CheckSymbolExists)
+check_symbol_exists(strlcpy "string.h" HAVE_STRLCPY)
+if(HAVE_STRLCPY)
+ add_definitions(-DHAVE_STRLCPY)
+endif()
+
diff --git a/userspace/common/strlcpy.h b/userspace/common/strlcpy.h
index 7a9f4436..950099d4 100644
--- a/userspace/common/strlcpy.h
+++ b/userspace/common/strlcpy.h
@@ -14,10 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
+#pragma once
+
#include <sys/types.h>
#include <string.h>
+#ifndef HAVE_STRLCPY
/*!
\brief Copy up to size - 1 characters from the NUL-terminated string src to dst, NUL-terminating the result.
@@ -40,3 +43,6 @@ static inline size_t strlcpy(char *dst, const char *src, size_t size) {
return srcsize;
}
+
+#endif
+
No musl:
With
|
Falco has a build variant that uses musl libc, and musl libc already defines strlcpy, so we don't want strlcpy when compiling with musl libc. So check for it at cmake time and if found set HAVE_STRLCPY. And only include the one in strlcpy.h if HAVE_STRLCPY is not defined. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
672c774
to
abf4d44
Compare
I updated the PR to check for strlcpy at cmake time as @deepskyblue86 suggested, please take a look again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@deepskyblue86 Thank you for the suggestion!
LGTM label has been added. Git tree hash: 06162cd850aac5d200d18f1d3e13e02fd0638b30
|
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: gnosek, mstemm The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Detect strlcpy on the fly, as was done in falcosecurity/libs#110. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Falco has a build variant that uses musl libc, and musl libc already
defines strlcpy, so we don't want strlcpy when compiling with musl
libc.
Unfortunately, musl doesn't have a define like _MUSL_SOURCE that we
could use to detect when compiling with musl libc. So instead, use
MINIMAL_BUILD, which when set always means compiling with musl libc.
Signed-off-by: Mark Stemm mark.stemm@gmail.com
What type of PR is this?
/kind bug
Any specific area of the project related to this PR?
/area build
/area libscap
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: