SELinux Security Module development
 help / color / mirror / Atom feed
From: Petr Lautrbach <lautrbach@redhat.com>
To: selinux@vger.kernel.org
Cc: Dustin Kirkland <dustin.kirkland@chainguard.dev>
Subject: Re: [PATCH] policycoreutils/secon: fix discarded-qualifiers warning with glibc 2.43
Date: Mon, 27 Apr 2026 14:47:22 +0200	[thread overview]
Message-ID: <878qa8tvs5.fsf@redhat.com> (raw)
In-Reply-To: <20260427123304.74899-1-lautrbach@redhat.com>

Petr Lautrbach <lautrbach@redhat.com> writes:

> From: Dustin Kirkland <dustin.kirkland@chainguard.dev>
>
> 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 #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 <dustin.kirkland@chainguard.dev>

Acked-by: Petr Lautrbach <lautrbach@redhat.com>


> ---
>
> Resent of the original patch downloaded from githu as the original patch in the
> email was slightly broken.
>
>  policycoreutils/secon/secon.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/policycoreutils/secon/secon.c b/policycoreutils/secon/secon.c
> index d624fa136f3e..9a05cf1959ba 100644
> --- a/policycoreutils/secon/secon.c
> +++ b/policycoreutils/secon/secon.c
> @@ -348,7 +348,7 @@ static int my_getXcon_raw(pid_t pid, char  **con, const char *val)
>  {
>  	char buf[4096];
>  	FILE *fp = NULL;
> -	const char *ptr = NULL;
> +	char *ptr = NULL;
>  
>  	snprintf(buf, sizeof(buf), "%s/%ld/attr/%s", "/proc", (long int)pid,
>  		 val);
> -- 
> 2.54.0


  reply	other threads:[~2026-04-27 12:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-12 15:08 [PATCH] policycoreutils/secon: fix discarded-qualifiers warning with glibc 2.43 Dustin Kirkland
2026-04-27 12:32 ` Petr Lautrbach
2026-04-27 12:47   ` Petr Lautrbach [this message]
2026-05-12 18:05     ` James Carter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878qa8tvs5.fsf@redhat.com \
    --to=lautrbach@redhat.com \
    --cc=dustin.kirkland@chainguard.dev \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox