[PATCH v3 04/27] adduser: replace BB_EXECLP call with BB_EXECVP

Kang-Che Sung explorer09 at gmail.com
Tue Jan 28 07:31:20 UTC 2025


On Tue, Jan 28, 2025 at 3:14 PM Nadav Tasher <tashernadav at gmail.com> wrote:
>
> Hi!
>
> I want to keep the signature of BB_EXECVPE similar to that of execvpe.
> I can make sure no other function modifies argv by making a copy of argv,
> which I will then pass to functions that expect char** (most notably
> run_noexec_applet_and_exit).
>
> Regarding all of the places where I modified calls to BB_EXECVP using
> newly created argvs, what should I change them to?
> I think they should be char**, and be cast to const char **.
> This seems safe to me.
>

If BB_EXECVPE internally copies the argv strings, the argument type of
"argv" should be "const char * []" or "const char **"
The "const" qualifiers are there to tell whether the strings will be
read-only or modifiable.

"char**" may be implicitly cast to "const char **", but the other way
around needs an explicit cast.
It's language design that keeps you safe. Unless you are dealing with
defective APIs (such as, when const qualifiers are left out in their
function prototypes), you probably don't need de-const casts most of
your time.


More information about the busybox mailing list