On Tue, Nov 23, 2021 at 1:46 PM Gert Doering <[email protected]> wrote:
> Hi,
>
> On Fri, Nov 19, 2021 at 02:53:06AM +0200, Lev Stipakov wrote:
> > + if ((install_path[wcslen(install_path) - 1]) == L'\\')
> > + {
> > + install_path[wcslen(install_path) - 1] = L'\0';
> > + }
> > +
> > + WCHAR openssl_cnf[MAX_PATH] = {0};
> > + WCHAR openssl_engines[MAX_PATH] = {0};
> > + WCHAR openssl_modules[MAX_PATH] = {0};
> > +
> > + openvpn_swprintf(openssl_cnf, _countof(install_path),
> > + L"OPENSSL_CONF=%ls\\ssl\\openssl.cnf", install_path);
>
> This needs to be _countof(openssl_cnf) - even if they are the same
> today, they might not be tomorrow.
>
> While at it, I wonder if it is more orderly to move the swprintf()
> calls in the "if NULL" clause now... like this:
>
> if (_wgetenv(L"OPENSSL_CONF") == NULL)
> {
> WCHAR openssl_cnf[MAX_PATH] = {0};
>
> openvpn_swprintf(openssl_cnf, _countof(openssl_cnf),
> L"OPENSSL_CONF=%ls\\ssl\\openssl.cnf", install_path);
> _wputenv(openssl_cnf);
> }
>
> (I would not have brought this up for a v4, but the _countof() needs
> to be fixed anyway)
>
If you are doing a v4 you may want to consider:
static struct {
wchar_t *name;
wchar_t *value;
} ossl_env[] = {{L"OPENSSL_CNF", L"openssl.cnf"},
{"OPENSSL_ENGINES", L"engines"},
{..}};
and use a loop. Less local arrays, easy to add more to the env zoo later
etc..
Just saying --- I'm okay with the current style too.
> Regarding Selva's comment on the scope of the memory passed to _wputenv(),
> I checked MS documentation, and it does not say anything.
>
MS docs say _putenv is their implementation of POSIX putenv but the latter
does imply the pointer supplied by the user should be used as is. Anyway,
if it works with automatics, good for us.
>
> OTOH, it points to _wputenv_s(varname,string) which might be worth
> considering...
>
+1 to that especially if MSVC is planning to deprecate _wputenv as they
have already done for a host of other such functions.
Selva
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel