diff mbox series

[2/2] libselinux: restorecon: avoid printing NULL pointer

Message ID 20220517140748.24238-2-cgzones@googlemail.com (mailing list archive)
State Accepted
Commit 956bda08f618
Headers show
Series [1/2] libselinux: restorecon: add fallback for pre 3.6 Linux | expand

Commit Message

Christian Göttsche May 17, 2022, 2:07 p.m. UTC
The variable `curcon` is NULL in case the file has no current security
context.  Most C standard libraries handle it fine, avoid it nonetheless
for standard conformance.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
"(null)" might not be the best token to display, it was only taken to
not change current behavior
---
 libselinux/src/selinux_restorecon.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

James Carter May 18, 2022, 1:54 p.m. UTC | #1
On Tue, May 17, 2022 at 3:20 PM Christian Göttsche
<cgzones@googlemail.com> wrote:
>
> The variable `curcon` is NULL in case the file has no current security
> context.  Most C standard libraries handle it fine, avoid it nonetheless
> for standard conformance.
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
> ---
> "(null)" might not be the best token to display, it was only taken to
> not change current behavior
> ---
>  libselinux/src/selinux_restorecon.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
> index 1a185ced..1b21a605 100644
> --- a/libselinux/src/selinux_restorecon.c
> +++ b/libselinux/src/selinux_restorecon.c
> @@ -771,7 +771,9 @@ static int restorecon_sb(const char *pathname, struct rest_flags *flags, bool fi
>                         selinux_log(SELINUX_INFO,
>                                     "%s %s from %s to %s\n",
>                                     updated ? "Relabeled" : "Would relabel",
> -                                   pathname, curcon, newcon);
> +                                   pathname,
> +                                   curcon ? curcon : "(null)",

Use "<<none>>", this is already used in file context files to indicate
a file should not have a label.

Thanks,
Jim

> +                                   newcon);
>
>                 if (flags->syslog_changes && !flags->nochange) {
>                         if (curcon)
> --
> 2.36.1
>
Christian Göttsche May 20, 2022, 12:46 p.m. UTC | #2
On Wed, 18 May 2022 at 15:54, James Carter <jwcart2@gmail.com> wrote:
>
> On Tue, May 17, 2022 at 3:20 PM Christian Göttsche
> <cgzones@googlemail.com> wrote:
> >
> > The variable `curcon` is NULL in case the file has no current security
> > context.  Most C standard libraries handle it fine, avoid it nonetheless
> > for standard conformance.
> >
> > Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
> > ---
> > "(null)" might not be the best token to display, it was only taken to
> > not change current behavior
> > ---
> >  libselinux/src/selinux_restorecon.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
> > index 1a185ced..1b21a605 100644
> > --- a/libselinux/src/selinux_restorecon.c
> > +++ b/libselinux/src/selinux_restorecon.c
> > @@ -771,7 +771,9 @@ static int restorecon_sb(const char *pathname, struct rest_flags *flags, bool fi
> >                         selinux_log(SELINUX_INFO,
> >                                     "%s %s from %s to %s\n",
> >                                     updated ? "Relabeled" : "Would relabel",
> > -                                   pathname, curcon, newcon);
> > +                                   pathname,
> > +                                   curcon ? curcon : "(null)",
>
> Use "<<none>>", this is already used in file context files to indicate
> a file should not have a label.

"<<none>>" used in file contexts definitions does not mean no security
context but never relabel the existing context.
Maybe something like "<no context>" or "<empty context>"?

>
> Thanks,
> Jim
>
> > +                                   newcon);
> >
> >                 if (flags->syslog_changes && !flags->nochange) {
> >                         if (curcon)
> > --
> > 2.36.1
> >
diff mbox series

Patch

diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
index 1a185ced..1b21a605 100644
--- a/libselinux/src/selinux_restorecon.c
+++ b/libselinux/src/selinux_restorecon.c
@@ -771,7 +771,9 @@  static int restorecon_sb(const char *pathname, struct rest_flags *flags, bool fi
 			selinux_log(SELINUX_INFO,
 				    "%s %s from %s to %s\n",
 				    updated ? "Relabeled" : "Would relabel",
-				    pathname, curcon, newcon);
+				    pathname,
+				    curcon ? curcon : "(null)",
+				    newcon);
 
 		if (flags->syslog_changes && !flags->nochange) {
 			if (curcon)