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

Kang-Che Sung explorer09 at gmail.com
Mon Jan 27 06:17:28 UTC 2025


On Mon, Jan 27, 2025 at 12:18 PM <d+busybox at adaptive-enterprises.com> wrote:
>
> Hi, Nadav
>
> The dominant style in the project seems to be char *v, not char* v.
>
> > +     passwd_argv[0] = (char *) "passwd";
> > +     passwd_argv[1] = (char *) "--";
> > +     passwd_argv[2] = (char *) login_name;
> > +     passwd_argv[3] = NULL;
>
> The type of a string literal is already char *, so the first two don't need
> the cast. You could even write it more compactly, like this:
>
>         char *passwd_argv[] = { "passwd", "--", (char *)login_name, NULL };
>

Technically, string literals are of type "const char *", not "char *".
And when you assign string literals to "char *" like that,
unpredictable behavior can happen when the strings get modified by
some other function.

Perhaps what you really intended is this?

const char *passwd_argv[] = { "passwd", "--", login_name, NULL };


More information about the busybox mailing list