[openssl-dev] [openssl.org #4489] PATCH: fix Windows deprecated strdup in crypto\conf\conf_lib.c

Richard Levitte via RT rt at openssl.org
Wed May 25 21:26:12 UTC 2016


On Tue Mar 29 12:02:41 2016, noloader at gmail.com wrote:
> >>> $ cat conf_lib.patch
> >>> diff --git a/crypto/conf/conf_lib.c b/crypto/conf/conf_lib.c
> >>> index f197714..7bc3ac0 100644
> >>> --- a/crypto/conf/conf_lib.c
> >>> +++ b/crypto/conf/conf_lib.c
> >>> @@ -392,7 +392,7 @@ void
> >>> OPENSSL_INIT_set_config_filename(OPENSSL_INIT_SETTINGS *settings,
> >>> const char *config_file)
> >>> {
> >>> free(settings->config_name);
> >>> - settings->config_name = config_file == NULL ? NULL :
> >>> strdup(config_file);
> >>> + settings->config_name = config_file == NULL ? NULL :
> >>> OPENSSL_strdup(config_file);
> >>> }
> >>> #endif
> >>
> >> If you're going to change strdup -> OPENSSL_strdup, then the
> >> previous
> >> line needs to also change free -> OPENSSL_free.
> >
> > Few lines up there is rationale for malloc/free and by association
> > strdup. Switching to OPENSSL_[strdup|malloc|free] goes against it. On
> > Windows one can/should switch to _strdup (it also solves another real
> > yet subtle problem, not just warning). If lack of strdup is concern
> > (relly? which Fedora, BSD, Linux can it be?), then one might have to
> > consider local few-liner implementation. And conf_sap.c suffers from
> > this too...
>
> The odd thing with this one was, the switch from strdup to _strdup
> should have occurred with the patch from Issue 4488 occurred. For some
> reason, the text substitution was not occurring, even after including
> the header "openssl/e_os.h" in conf_lib.c.

It should be just "e_os.h"

I just tried, and it worked. With your patch, no more ISO C++ function
warnings.

I'll make a pull request in a few...

>
> I'm probably missing some other interaction among the headers.
>
> For completeness, below is the thrust of the 4488 patch. If
> Microsoft's compiler is from Visual Studio 2003 or above, then follow
> Microsoft's recommendations reported in the warning.
>
> ***********
>
> $ git diff e_os.h > e_os.patch
> $ cat e_os.patch
> diff --git a/e_os.h b/e_os.h
> index f0a441e..1fe3ffb 100644
> --- a/e_os.h
> +++ b/e_os.h
> @@ -520,6 +520,13 @@ struct servent *PASCAL getservbyname(const char
> *, const char *);
> # if defined(OPENSSL_SYS_WINDOWS)
> # define strcasecmp _stricmp
> # define strncasecmp _strnicmp
> +# if (_MSC_VER >= 1310)
> +# define open _open
> +# define fdopen _fdopen
> +# define close _close
> +# define strdup _strdup
> +# define unlink _unlink
> +# endif
>
> # elif defined(OPENSSL_SYS_VMS)
> /* VMS below version 7.0 doesn't have strcasecmp() */
> # include "internal/o_str.h"


--
Richard Levitte
levitte at openssl.org

-- 
Ticket here: http://rt.openssl.org/Ticket/Display.html?id=4489
Please log in as guest with password guest if prompted



More information about the openssl-dev mailing list