Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#55499 closed enhancement (fixed)

mingw-w64: missing secure api support

Reported by: bruvzg Owned by: mojca (Mojca Miklavec)
Priority: Normal Milestone:
Component: ports Version:
Keywords: Cc:
Port: mingw-w64

Description

mingw-w64 port is currently configured without --enable-secure-api, so projects with "security-enhanced" (_s) functions fails to build. Major Linux distributions, MSYS2 and Cygwin build MinGW with --enable-secure-api for both i686 and x86_64 targets.

I would like to suggest adding --enable-secure-api configuration flag.

Change History (11)

comment:1 Changed 7 years ago by mf2k (Frank Schima)

Cc: mojca@… removed
Owner: set to mojca
Port: mingw-w64 added
Status: newassigned

In the future, please fill in the Port field.

comment:2 Changed 7 years ago by mojca (Mojca Miklavec)

Status: assignedaccepted

comment:3 Changed 7 years ago by mojca (Mojca Miklavec)

Resolution: fixed
Status: acceptedclosed

In 6196ddb9f195aba0cac0cc474fbb86125dbb870b/macports-ports:

*-w64-mingw32-gcc: build with --enable-secure-api

Closes: #55499

comment:4 Changed 7 years ago by mojca (Mojca Miklavec)

Thanks for pointing this out.

comment:5 Changed 7 years ago by bruvzg

--enable-secure-api should be added to -headers subport, instead of -gcc!

comment:6 Changed 7 years ago by mojca (Mojca Miklavec)

I'm sorry. Can you please send me an example to test the functionality?

comment:7 Changed 7 years ago by bruvzg

Example:

#include <cstdio>

int main( void ) {
        FILE *stream = NULL;
        errno_t err = fopen_s( &stream, "data", "w+" );
        if( err != 0 ) printf( "File 'data' was not opened\n" );
        if( stream ) fclose( stream );
}

x86_64-w64-mingw32-gcc fopen_s.cpp -o fopen_s.exe without --enable-secure-api produce:

fopen_s.cpp: In function ‘int main()’:
fopen_s.cpp:5:16: error: ‘fopen_s’ was not declared in this scope
  errno_t err = fopen_s( &stream, "data", "w+" );
                ^~~~~~~
fopen_s.cpp:5:16: note: suggested alternative: ‘fopen64’
  errno_t err = fopen_s( &stream, "data", "w+" );
                ^~~~~~~
                fopen64

Builds with --enable-secure-api or with explicitly declared CXXFLAGS=-DMINGW_HAS_SECURE_API.

Actual project I had problems with: https://github.com/syoyo/tinyexr

comment:8 Changed 7 years ago by mojca (Mojca Miklavec)

Resolution: fixed
Status: closedreopened

comment:9 Changed 7 years ago by mojca (Mojca Miklavec)

Quote from chromium:

Windows XP does not provide secure API functions in msvcrt.dll but newer versions of Windows do. Avoid using secure API functions for compatibility with msvcrt.dll on Windows XP.

I guess XP is not too relevant, but it would be nice to update the build docs and at least mention a few words about what those flags do and why users might want to enable them by default.

comment:10 Changed 7 years ago by mojca (Mojca Miklavec)

Resolution: fixed
Status: reopenedclosed

In 1f43f83ce6346fb0c9163a8ecf8125faaa18aab6/macports-ports:

mingw-w64: update to gcc 7.3.0, secure api support

Closes: #55499

comment:11 Changed 7 years ago by mojca (Mojca Miklavec)

Please let me know in case this didn't solve the problem.

Note: See TracTickets for help on using tickets.