@@ -103,6 +103,12 @@ FTS_LDLIBS ?=
override CFLAGS += -I../include -D_GNU_SOURCE $(DISABLE_FLAGS) $(PCRE_CFLAGS)
+# check for strlcpy(3) availability
+H := \#
+ifeq (yes,$(shell printf '${H}include <string.h>\nint main(void){char*d,*s;strlcpy(d, s, 0);return 0;}' | $(CC) -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
+override CFLAGS += -DHAVE_STRLCPY
+endif
+
SWIG_CFLAGS += -Wno-error -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter \
-Wno-shadow -Wno-uninitialized -Wno-missing-prototypes -Wno-missing-declarations \
-Wno-deprecated-declarations
new file mode 100644
@@ -0,0 +1,18 @@
+#include "selinux_internal.h"
+
+#include <string.h>
+
+
+#ifndef HAVE_STRLCPY
+size_t strlcpy(char *dest, const char *src, size_t size)
+{
+ size_t ret = strlen(src);
+
+ if (size) {
+ size_t len = (ret >= size) ? size - 1 : ret;
+ memcpy(dest, src, len);
+ dest[len] = '\0';
+ }
+ return ret;
+}
+#endif /* HAVE_STRLCPY */
@@ -94,4 +94,8 @@ extern int selinux_page_size ;
extern int has_selinux_config ;
+#ifndef HAVE_STRLCPY
+size_t strlcpy(char *dest, const char *src, size_t size);
+#endif
+
#endif /* SELINUX_INTERNAL_H_ */
To copy string safely, by always NULL-terminating them, and provide an easy way to check for truncation introduce the nonstandard function strlcpy(3). Use the system implementation if available. Signed-off-by: Christian Göttsche <cgzones@googlemail.com> --- libselinux/src/Makefile | 6 ++++++ libselinux/src/selinux_internal.c | 18 ++++++++++++++++++ libselinux/src/selinux_internal.h | 4 ++++ 3 files changed, 28 insertions(+) create mode 100644 libselinux/src/selinux_internal.c