From: "Rahul Sandhu" <nvraxn@gmail.com>
To: "William Roberts" <bill.c.roberts@gmail.com>
Cc: <selinux@vger.kernel.org>
Subject: Re: [PATCH] libsemanage: define basename macro for non-glibc systems
Date: Fri, 21 Feb 2025 05:52:28 +0000 [thread overview]
Message-ID: <D7XW1Q3407I9.2LRX5QH5BAHGX@gmail.com> (raw)
In-Reply-To: <CAFftDdpV-dnLKVTDACgm2RUG8gnBU=3YnJDp5_ZyvR78p0eZdw@mail.gmail.com>
> What system are you on where you run libsemange without glibc, just curious?
All Gentoo machines, Gentoo musl. :)
> I am not opposed to adding an implementation for basename where the
> input can be read only for non-glibc, but this patch doesn't work:
> Per the man page, https://man7.org/linux/man-pages/man3/basename.3.html,
> basename("/") should return "/", this one return "\0"
> basename("/usr/"); should return "usr", this returns "\0".
> There are two ways you could approach this:
> 1. If you wanted to do an implementation, I would add it to
> utilities.c/h and call it something other than basename so we don't
> get any odd issues with it choosing the one from the headers over the
> macro. Perhaps libsemange_basename(). On glibc systems this would just
> call basename directly and on non-glibc systems do the implementation
> with your own logic.
> 2. Just copy the path into a modifiable buffer on non-glibc systems
>
> I would do both approaches. Create a utility routine that calls
> basename for glibc and for non-glibc just copies it to a modifiable
> buffer and then calls basename over rolling our own and the bugs
> associated with it, also add a unit test for this. This would keep the
> logic in one place and be dirt simple.
FWIW, glibc's basename appears to be really trivial:
char *
__basename (const char *filename)
{
char *p = strrchr (filename, '/');
return p ? p + 1 : (char *) filename;
}
> selinux_policy_root() returns a const char *,
> the usage in direct_api.c path is a char *, so we only need one spot
> changed and that can just be a simple
> copy to an intermediate buffer or am I missing something else here
> you're pointing out?
Oh good point, we're just missing a header (libgen.h).
I suppose then it is just a simple copy to an intermediate buffer, I'll
send an updated patch shortly.
Thanks,
Rahul
next prev parent reply other threads:[~2025-02-21 5:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-20 21:12 [PATCH] libsemanage: define basename macro for non-glibc systems Rahul Sandhu
2025-02-21 0:16 ` William Roberts
2025-02-21 0:50 ` William Roberts
2025-02-21 5:52 ` Rahul Sandhu [this message]
2025-02-21 9:03 ` Rahul Sandhu
2025-02-21 9:39 ` [PATCH v2] libsemanage: create semanage_basename to ensure posix compliance Rahul Sandhu
2025-03-08 23:24 ` Rahul Sandhu
2025-03-19 19:29 ` James Carter
2025-04-07 18:06 ` 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=D7XW1Q3407I9.2LRX5QH5BAHGX@gmail.com \
--to=nvraxn@gmail.com \
--cc=bill.c.roberts@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.