* Move it into separate win32_snprintf.h file to de-duplicate its
implementation from all miniupnp source files.
* Do not use this emulation with mingw32 SDK when __NO_ISOCEXT is not
defined as in this case mingw32 provides working snprintf function.
* Fix detection for mingw-w64 variants, when __NO_ISOCEXT is defined or
when older version without UCRT is used.
* Add check if _scprintf function is available. In case it is not available
just returns length of filled buffer to prevent buffer overflow.
_snprintf() differs from snprintf() in:
* on overflow it returns -1 instead of required buffer size
* on overflow it does not fill nul byte
* does not accept NULL/0 as a buffer
Microsoft implemented snprintf() in Visual Studio 2015 as part of UCRT.
Mingw32 contains snprintf() implementation only when __USE_MINGW_ANSI_STDIO
is defined.
Mingw-w64 versions prior to 8.0.0. contain snprintf() implementation when
__USE_MINGW_ANSI_STDIO or _UCRT is defined. Since version 8.0.0 it is
always supported.
Mingw-w64 defines both __MINGW32__ and __MINGW64_VERSION_MAJOR macros.
Mingw32 defines only __MINGW32__.
_scprintf() just count number of bytes needed for formatting string, so it
is basically return value of snprintf().
This change updates miniupnpc code to use snprintf() when is provided by
compiler/runtime to avoid usage _snprintf().
And also this changes updates miniupnpc emulation of snprintf() by
_snprintf() and _scprintf() functions to avoid buffer overflows.
For inspiration full emulation of snprintf() by _snprintf() is available in
mingw-w64 stdio library:
https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/stdio/snprintf.c
Check for 0.0.0.0, 192.168., 10. and 172. is not enough. Nowadays routers
behind NAT are getting IP address from shared CG-NAT space 100.64.0.0/10.
This patch adjust miniupnpc to check for all reserved IPv4 addresses.
Details :
cast for connect() sendto() arguments
remove unecessary p = NULL;
remove unecessary code
printf format fixes in ssdpDiscoverDevices()
fixes#311
Signed-off-by: Thomas Bernard <miniupnp@free.fr>
Account exactly for bytes when building buffer in simpleUPnPcommand2.
The margin of 100 is not guaranteed to always be enough. When long
parameters are passed in, it was possible to overflow the buffer.
See https://github.com/miniupnp/miniupnp/issues/119
- Replace the sameport parameter to the upnpDiscover* functions
- Added constants UPNP_LOCAL_PORT_ANY(0) & UPNP_LOCAL_PORT_SAME(1). The
value "1" was chosen for presumed backwards compatability with the
previous "sameport" parameter (assuming usesr would have set to 1 if
they wanted same port)
- Can be specified with "-z" to the test programs "upnpc" & "pymoduletest.py"
32bit: sizeof(&ifindex) == sizeof(void *) == 4
64bit: sizeof(&ifindex) == sizeof(void *) == 8
As a result, it is "ifindex" oob acces on 64bit platforms.