Commit Graph

25 Commits

Author SHA1 Message Date
Pali Rohár 7d5fdf0743 miniupnpc: Fix usage of Windows _snprintf() function
_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
2020-10-02 22:32:36 +02:00
Thomas Bernard 5f85321084 connecthostport.c: output to help debug
see #396
2019-10-13 19:22:59 +02:00
Thomas Bernard 422d42357e
use strncmp() instead of memcmp() when needed
memcmp(s1, s2, l) is valid when both s1 and s2
have at least l bytes acccessible. So
memcmp("a", "abcdefgh", 8)
is not valid

see #362
2019-04-23 14:16:25 +02:00
Thomas Bernard b725f5114f
connecthostport.c: code simplification 2019-03-10 19:23:58 +01:00
Cameron Gutman 3d4661635e Fix connect() socket error trace on Windows
closesocket() clobbers the Winsock last error value, so we must only call it after tracing.
2019-03-05 23:30:24 -08:00
Thomas Bernard 2656f41c7a
miniupnpc: set timeout for select() in connecthostport() 2019-01-23 09:44:21 +01:00
irwir d8c6433c2e Move common definition to miniupnpc_socketdef.h 2018-07-14 13:39:01 +02:00
irwir bded13f390 When code was updated for 64-bit Windows configurations, some changes were not applied.
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>
2018-07-06 11:35:12 +02:00
Thomas Bernard 284db0bb49 miniupnpc: use SOCKET type instead of int for copilation under Win64
see #289
2018-04-06 12:21:36 +02:00
Matthieu Nottale af5c091002 Send error logs to stderr. 2017-04-21 11:25:49 +02:00
Thomas Bernard d36853118e connecthostport.c: fix compilation with -DNO_GETADDRINFO 2017-03-13 14:34:16 +01:00
Thomas Bernard 6bbdb817f7 miniupnpc: update Changelog.txt and 2015=>2016 2016-12-16 09:59:10 +01:00
Thomas Bernard c39dda549d better error msg for setsockopt() calls 2016-11-11 10:13:48 -05:00
Thomas Bernard be9ab60dea 2014=>2015 :) 2015-11-05 12:36:33 +01:00
Thomas Hipp 3c78e9c78c miniupnpc: fix while-loop condition 2015-10-09 15:18:08 +02:00
Thomas BERNARD 3fc23c3b88 fix miniupnpc compilation under OS X 10.4 (darwin 8) 2015-10-01 23:37:05 +02:00
Thomas Bernard 28e3bda6dd miniupnpc/connecthostport.c: fix for compilation with SunOS 2014-10-06 14:42:28 +02:00
Thomas Bernard f354f73238 miniupnpc/connecthostport.c: handle EINPROGRESS after connect() 2014-02-05 18:31:28 +01:00
Thomas Bernard b0c66c01e2 miniupnpc: define MAXHOSTNAMELEN if not already done 2013-12-09 09:31:04 +01:00
Maciej Małecki cc165a7aa3 Fix Solaris (SmartOS) build
* On Solaris `fd_set` is defined in `sys/select.h`.
  * `libsocket`, `libnsl` and `libresolv` are required.

This makes it build cleanly if `MINIUPNPC_SET_SOCKET_TIMEOUT` is forced
to `false` (as tested on Joyent's SmartOS).
2013-05-03 07:40:26 +02:00
Thomas Bernard b8953b8414 miniupnpc/connecthostport.c: include netinet/in.h 2012-06-28 21:03:10 +02:00
Thomas Bernard c585986d2f miniupnpc: parseURL()/miniwget() : IPv6 addresses scope 2012-06-24 00:55:31 +02:00
Shawn Landen 6e14420ab1 remove trailing whitespace from miniupnpc 2012-02-29 17:51:24 -08:00
Thomas Bernard 35e25ab375 Replaced WIN32 macro by _WIN32 2012-01-21 14:38:38 +01:00
Thomas Bernard c183a72c46 Added miniupnpc 2011-09-27 22:25:35 +02:00