[openwrt/openwrt] libsemanage: update to 3.8.1 and fix build with GCC14
LEDE Commits
lede-commits at lists.infradead.org
Fri May 2 10:15:51 PDT 2025
robimarko pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/7c6a3e2dde50149841a77d001eddaf95a11fd0fd
commit 7c6a3e2dde50149841a77d001eddaf95a11fd0fd
Author: Robert Marko <robimarko at gmail.com>
AuthorDate: Thu May 1 21:25:14 2025 +0200
libsemanage: update to 3.8.1 and fix build with GCC14
Update libsemanage to latest 3.8.1 release and add an upstream backport[1]
that fixes compilation with GCC14 due to basename.
[1] https://github.com/SELinuxProject/selinux/commit/a339594da6f027aed5d66ec6798a3d732df235e4
Link: https://github.com/openwrt/openwrt/pull/18674
Signed-off-by: Robert Marko <robimarko at gmail.com>
---
package/libs/libsemanage/Makefile | 5 +-
...-create-semanage_basename-to-ensure-posix.patch | 157 +++++++++++++++++++++
2 files changed, 159 insertions(+), 3 deletions(-)
diff --git a/package/libs/libsemanage/Makefile b/package/libs/libsemanage/Makefile
index 9ebf9a6f21..87f3bb9518 100644
--- a/package/libs/libsemanage/Makefile
+++ b/package/libs/libsemanage/Makefile
@@ -6,12 +6,12 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=libsemanage
-PKG_VERSION:=3.5
+PKG_VERSION:=3.8.1
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://github.com/SELinuxProject/selinux/releases/download/$(PKG_VERSION)
-PKG_HASH:=f53534e50247538280ed0d76c6ce81d8fb3939bd64cadb89da10dba42e40dd9c
+PKG_HASH:=7b39127b219cc70bfd935a4af6b0f2ba83d4b35c916f253c7e942c23ab490f07
PKG_MAINTAINER:=Thomas Petazzoni <thomas.petazzoni at bootlin.com>
PKG_LICENSE:=LGPL-2.1
PKG_LICENSE_FILES:=COPYING
@@ -49,7 +49,6 @@ HOST_MAKE_FLAGS += \
DESTDIR=$(STAGING_DIR_HOSTPKG) \
PREFIX=""
-
define Build/Configure
endef
diff --git a/package/libs/libsemanage/patches/0001-libsemanage-create-semanage_basename-to-ensure-posix.patch b/package/libs/libsemanage/patches/0001-libsemanage-create-semanage_basename-to-ensure-posix.patch
new file mode 100644
index 0000000000..5240b3dabc
--- /dev/null
+++ b/package/libs/libsemanage/patches/0001-libsemanage-create-semanage_basename-to-ensure-posix.patch
@@ -0,0 +1,157 @@
+From a339594da6f027aed5d66ec6798a3d732df235e4 Mon Sep 17 00:00:00 2001
+From: Rahul Sandhu <nvraxn at gmail.com>
+Date: Fri, 21 Feb 2025 09:39:10 +0000
+Subject: [PATCH] libsemanage: create semanage_basename to ensure posix
+ compliance
+
+Passing a const char * to basename(3) is a glibc-specific extension, so
+create our own basename implementation. As it's a trivial 2 LOC, always
+use our implementation of basename even if glibc is available to avoid
+the complications of attaining the non-posix glibc implementation of
+basename(3) as _GNU_SOURCE needs to be defined, but libgen.h also needs
+to have not been included.
+
+Also fix a missing check for selinux_policy_root(3). From the man page:
+On failure, selinux_policy_root returns NULL.
+
+As the glibc basename(3) (unlike posix basename(3)) does not support
+having a nullptr passed to it, only pass the policy_root to basename(3)
+if it is non-null.
+
+Signed-off-by: Rahul Sandhu <nvraxn at gmail.com>
+Acked-by: James Carter <jwcart2 at gmail.com>
+---
+ src/conf-parse.y | 13 ++++++++++---
+ src/direct_api.c | 1 +
+ src/utilities.c | 9 +++++++++
+ src/utilities.h | 13 +++++++++++++
+ tests/test_utilities.c | 26 ++++++++++++++++++++++++++
+ 5 files changed, 59 insertions(+), 3 deletions(-)
+
+--- a/src/conf-parse.y
++++ b/src/conf-parse.y
+@@ -21,6 +21,7 @@
+ %{
+
+ #include "semanage_conf.h"
++#include "utilities.h"
+
+ #include <sepol/policydb.h>
+ #include <selinux/selinux.h>
+@@ -382,7 +383,10 @@ external_opt: PROG_PATH '=' ARG { PAS
+ static int semanage_conf_init(semanage_conf_t * conf)
+ {
+ conf->store_type = SEMANAGE_CON_DIRECT;
+- conf->store_path = strdup(basename(selinux_policy_root()));
++ const char *policy_root = selinux_policy_root();
++ if (policy_root != NULL) {
++ conf->store_path = strdup(semanage_basename(policy_root));
++ }
+ conf->ignoredirs = NULL;
+ conf->store_root_path = strdup("/var/lib/selinux");
+ conf->compiler_directory_path = strdup("/usr/libexec/selinux/hll");
+@@ -544,8 +548,11 @@ static int parse_module_store(char *arg)
+ free(current_conf->store_path);
+ if (strcmp(arg, "direct") == 0) {
+ current_conf->store_type = SEMANAGE_CON_DIRECT;
+- current_conf->store_path =
+- strdup(basename(selinux_policy_root()));
++ const char *policy_root = selinux_policy_root();
++ if (policy_root != NULL) {
++ current_conf->store_path =
++ strdup(semanage_basename(policy_root));
++ }
+ current_conf->server_port = -1;
+ } else if (*arg == '/') {
+ current_conf->store_type = SEMANAGE_CON_POLSERV_LOCAL;
+--- a/src/direct_api.c
++++ b/src/direct_api.c
+@@ -26,6 +26,7 @@
+
+ #include <assert.h>
+ #include <fcntl.h>
++#include <libgen.h>
+ #include <stdio.h>
+ #include <stdio_ext.h>
+ #include <stdlib.h>
+--- a/src/utilities.c
++++ b/src/utilities.c
+@@ -349,3 +349,12 @@ int write_full(int fd, const void *buf,
+
+ return 0;
+ }
++
++#ifdef __GNUC__
++__attribute__((nonnull))
++#endif
++char *semanage_basename(const char *filename)
++{
++ char *p = strrchr(filename, '/');
++ return p ? p + 1 : (char *)filename;
++}
+--- a/src/utilities.h
++++ b/src/utilities.h
+@@ -156,4 +156,17 @@ semanage_list_t *semanage_slurp_file_fil
+
+ int write_full(int fd, const void *buf, size_t len) WARN_UNUSED;
+
++/**
++ * Portable implementation of the glibc version of basename(3).
++ *
++ * @param filename path to find basename of
++ *
++ * @return basename of filename
++ */
++
++#ifdef __GNUC__
++__attribute__((nonnull))
++#endif
++char *semanage_basename(const char *filename);
++
+ #endif
+--- a/tests/test_utilities.c
++++ b/tests/test_utilities.c
+@@ -46,6 +46,7 @@ static void test_semanage_rtrim(void);
+ static void test_semanage_str_replace(void);
+ static void test_semanage_findval(void);
+ static void test_slurp_file_filter(void);
++static void test_semanage_basename(void);
+
+ static char fname[] = {
+ 'T', 'E', 'S', 'T', '_', 'T', 'E', 'M', 'P', '_', 'X', 'X', 'X', 'X',
+@@ -117,6 +118,10 @@ int semanage_utilities_add_tests(CU_pSui
+ test_slurp_file_filter)) {
+ goto err;
+ }
++ if (NULL == CU_add_test(suite, "semanage_basename",
++ test_semanage_basename)) {
++ goto err;
++ }
+ return 0;
+ err:
+ CU_cleanup_registry();
+@@ -346,3 +351,24 @@ static void test_slurp_file_filter(void)
+
+ semanage_list_destroy(&data);
+ }
++
++static void test_semanage_basename(void)
++{
++ char *basename1 = semanage_basename("/foo/bar");
++ CU_ASSERT_STRING_EQUAL(basename1, "bar");
++
++ char *basename2 = semanage_basename("/foo/bar/");
++ CU_ASSERT_STRING_EQUAL(basename2, "");
++
++ char *basename3 = semanage_basename("/foo.bar");
++ CU_ASSERT_STRING_EQUAL(basename3, "foo.bar");
++
++ char *basename5 = semanage_basename(".");
++ CU_ASSERT_STRING_EQUAL(basename5, ".");
++
++ char *basename6 = semanage_basename("");
++ CU_ASSERT_STRING_EQUAL(basename6, "");
++
++ char *basename7 = semanage_basename("/");
++ CU_ASSERT_STRING_EQUAL(basename7, "");
++}
More information about the lede-commits
mailing list