policycoreutils/secon: fix discarded-qualifiers warning with glibc 2.43#507
Open
dustinkirkland wants to merge 1 commit intoSELinuxProject:mainfrom
Open
Conversation
In my_getXcon_raw(), ptr is declared as const char * but is assigned from fgets(), which returns char *. With glibc 2.43, strchr(const char *, int) now returns const char *, so the subsequent assignment to char *tmp triggers: secon.c:365:18: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers] The const on ptr was always incorrect: fgets() returns a mutable pointer into buf (a char[4096]), and the result of strchr() through ptr is written to via *tmp = 0. Remove the erroneous const. This is the same class of bug reported in issue SELinuxProject#506 (libselinux/src/selinux_config.c:284). The fix here is analogous: the variable should not have been const-qualified in the first place. Signed-off-by: Dustin Kirkland <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
my_getXcon_raw(),ptris declared asconst char *but isassigned from
fgets(), which returnschar *. With glibc 2.43,strchr(const char *, int)now correctly returnsconst char *(matching the constness of its input), so the subsequent assignment
to
char *tmptriggers a build failure:This breaks builds on any system with glibc 2.43+ and gcc with
-Werror(which the SELinux Makefile uses).Fix
The
constonptrwas always incorrect:fgets()returnschar *(a mutable pointer intobuf, which ischar[4096])strchr()throughptris immediately used mutably:*tmp = 0Remove the erroneous
constqualifier fromptr.Relation to issue #506
This is the same class of bug reported in #506
(
libselinux/src/selinux_config.c:284). That issue coversstrrchr()inselinux_set_policy_root(); this patch coversstrchr()inmy_getXcon_raw()inpolicycoreutils/secon/secon.c.Both instances have the same root cause: a local variable was
unnecessarily
const-qualified, which glibc 2.43's strengthenedstrchr/strrchrconst-propagation now correctly rejects.Testing
Verified by building
policycoreutilsversion 3.10 against glibc 2.43on a Wolfi-based system (Chainguard) where this was a build failure.
Signed-off-by: Dustin Kirkland [email protected]