Commit Graph

2990 Commits

Author SHA1 Message Date
Deomid Ryabkov
afcb4d9df7 Do not post MG_SIG_CLOSE_CONN if the conn is already closing 2022-10-09 16:36:51 +01:00
Deomid Ryabkov
44b15b76f7 Fix leaking non-active (e.g., bound) LWIP TCP PCBs
tcp_close_tcpip() only closed active TCP PCBs, leaking other types of TCP PCBs
(notably bound only, not yet connected/used).  With time, this led to DoS
situations.

Fix by giving up on the hacky way of searching the LWIP innards for the TCP PCB
needing closing.  The searching was non-comprehensive, hence the problem in
principle, and inherently racy: could close a meanwhile freed & reused PCB.

Pass the pointer to the struct mg_lwip_conn_state of the struct mg_connection
being destroyed to tcp_close_tcpip() instead of the bare PCB pointer, so the PCB
pointer stored within can be used.  Delay unassigning that pointer from the
struct mg_connection until tcp_close_tcpip() finishes, so that
a mg_lwip_tcp_error_cb() meanwhile can clear the PCB pointer stored within.
That ensures no double-closing of the TCP PCB when a concurrent TCP error makes
LWIP close the TCP PCB from the LWIP side.

NB!  At the moment, PCBs can still leak if tcp_close() fails, which is unlikely
but possible as per the API.  Retrying tcp_close() should somehow be
implemented.  For now, at least add logging of tcp_close() failures.

Also: remove the extraneous though benign double-calling of tcp_arg(…, NULL).

h/t @QRPp
2022-09-27 09:20:15 +01:00
Deomid Ryabkov
a1fcbb0718 Fix WS connections to URLs that don't end in /
Same as in mg_connect_http_opt().
2022-08-03 14:39:55 +01:00
Deomid Ryabkov
0c4d364cee LWIP: Fix races between TCP errors and queued callbacks
A TCP connection can get closed while there are TCPIP thread callbacks
queued. Add checks to close and write functions to avoid acting on
tcp_pcbs that have already been disposed of.
2022-06-14 21:27:24 +01:00
Deomid Ryabkov
def2f39724 lwip: Check for accepted connection being NULL
This happens when lwip runs out of pcbs and just communicates an error.
2021-11-24 02:43:42 +00:00
Deomid Ryabkov
311fdb8bac lwip: Optimize UDP RX path and introduce a limit
Store adddress in the memory immediately preceding the packet data.
It is guaranteed to have enough space (IP header is 20 bytes).

Introduce a limit on the length of the RX chain,
MG_LWIP_MAX_UDP_RX_CHAIN_LEN. Default is 20.
2021-09-01 22:25:36 +01:00
Deomid Ryabkov
38f694d071 Update README 2021-06-12 02:00:49 +01:00
Deomid "rojer" Ryabkov
da1e5438bd LWIP: (Ab)use mg_conection.priv_2 to pass input interface address
This is required to distinguish input interface for multicast traffic
and select correct output interface for outgoing traffic (advertisements).

http://savannah.nongnu.org/bugs/?49662 removed ability to receive
multicast traffic on on interface-bound sockets (making the previous
change useless, hence the revert), so for LWIP 2.0.1 and newer
multicast packets can only be received on INADDR_ANY listeners.
User is then required to distinguish input interface in the receive path.
This information is only available in the udp_recv callback, so we must
pass this down to dns-sd library somehow, and priv_2 is the how.
It is normally used for DNS resolver state, and is never used on
listening sockets. We thus avoid growing the mg_connection structure.
2021-06-12 01:58:08 +01:00
Deomid "rojer" Ryabkov
e3a140c9a7 Add ability to enumerate endpoints 2021-06-12 01:56:50 +01:00
Deomid "rojer" Ryabkov
a350208f35 Add SHA256 support for digest auth
https://tools.ietf.org/html/rfc7616
2021-06-12 01:56:29 +01:00
Deomid "rojer" Ryabkov
6fa305e36d Remove ESP8266 pbuf chain length check
It's been pushed up to LWIP: f92662566e
2021-06-12 01:56:10 +01:00
Deomid "rojer" Ryabkov
edd38f6ccd mongoose: Read file data directly into send_mbuf
Reduces stack usage and avoids an extra copy
2021-06-12 01:55:44 +01:00
Deomid "rojer" Ryabkov
abced77c24 Remove NUL-temrination from cs_base64_{encode,decode} functions
Preserve for the corresponding `mg_*` variants for compatibility.
2021-06-12 01:54:51 +01:00
Deomid "rojer" Ryabkov
4699e90e99 Ensure struct mg_connect_opts size remains the same, SSL or not
It is passed by value so libraries compiled with and without SSL cannot interoperate if struct size is different.
2021-06-12 01:54:32 +01:00
Deomid "rojer" Ryabkov
e9853be8f7 Reduce the size of struct mg_dns_message
From 2K to 1K. Still too big for most cases but manageable.
2021-06-12 01:54:21 +01:00
Deomid "rojer" Ryabkov
fd062b530c Fix a memory leak in mg_lwip_if
When a UDP listener is closed, pending pbufs must be freed.
This was causing a leak on flappy wifi connections and dns-sd enabled.
2021-06-12 01:46:48 +01:00
Deomid "rojer" Ryabkov
2fbfe61c37 Fix connection management bugs in mg_lwip_if
* Do not set MG_F_SSL ona connection until it's been fully accepted (MG_SIG_ACCEPT is handled).
   This fixes a crash when SSL connection is polled before it's fully initialized.
 * Fix mg_lwip_tcp_error_cb to NULL out tcp_pcb pointer even if mg_connection is already shutting down.
   After mg_lwip_tcp_error_cb, tcp_pcb pointer can no longer be used and doesn't need to be freed.
   This fixes https://github.com/cesanta/mongoose-os/issues/545
2021-06-12 01:45:30 +01:00
Deomid "rojer" Ryabkov
70034b5873 Fix stack overflow when serving http files on ESP8266
ESP8266 non-OS has very limited stack - only 4K. Undetected stack
overflows cause nasty bugs and it turns out serving files over http
routinely causes stack overflow.

This was exposed by a5f59123ed

As a short-term workaround, push http_message into bss, this is enough
as an immediate workaround. Longer term, we need to think how to bring
8266 to parity with other platforms where we have at least 8K stack.

At the same time, get rid of the compiler bug workaround - modern
toolchain doesn't need this.
2021-06-12 00:30:51 +01:00
Deomid Ryabkov
d6c9d3c181 Fix amalgam/unamalgam diffs 2021-06-12 00:22:26 +01:00
Sergey Lyubka
34d4fb8cf0
Merge pull request #1157 from rojer/qq
Add mg_next_query_string_entry_n() and mg_url_decode_n()
2020-10-26 13:25:31 +00:00
Deomid Ryabkov
be64f81eee Add mg_next_query_string_entry_n() and mg_url_decode_n()
Move to mg_util.h so encode and decode are next ot each other.

Pull out mg_next_list_entry_n() for advanced use cases.

Add unit tests.
2020-10-24 22:53:50 +01:00
Sergey Lyubka
9fe1c93c9b
Merge pull request #1143 from rojer/cs_log_lock
Add cs_log_{lock,unlock}
2020-08-28 20:46:37 +01:00
Deomid Ryabkov
a4b6d58b24 Add cs_log_{lock,unlock}
In implementatiosn that have preemptive scheduelrs these can be implemented
to ensure logging from different threads is properly serialized.
2020-08-28 20:29:13 +01:00
Sergey Lyubka
86f391c701
Merge pull request #1139 from rojer/warns
Fix warnings and sync line numbers of unamalgamated sources
2020-08-20 00:45:02 +01:00
Sergey Lyubka
36de38bd11
Merge pull request #1138 from rojer/1135
Add missing range check in mg_get_http_header()
2020-08-20 00:44:36 +01:00
Deomid Ryabkov
a308872c88 Fix warnings and sync line numbers of unamalgamated sources 2020-08-19 22:02:50 +01:00
Deomid Ryabkov
a369160296 Add missing range check in mg_get_http_header()
h/t BushraAloraini

Fixes https://github.com/cesanta/mongoose/issues/1135
2020-08-19 21:48:45 +01:00
Sergey Lyubka
0a09b46c94
Merge pull request #1128 from rojer/amalgam
Sync src with amalgamated versions
2020-07-12 15:32:42 +01:00
Deomid Ryabkov
b0a1cd7b0d Sync src with amalgamated versions
Now src contains exactly what's embedded in mongoose.c and .h, nothing more.

Added `tools/amalgam.sh` to aamlgamate both files at once.

There are no functional changes to mongoose.c, .h in this PR, only slight filename changes.
2020-07-08 02:08:49 +01:00
novlean
73a2b92278
Merge pull request #1124 from cesanta/novlean-patch-1
added MWS white paper
2020-06-24 17:08:49 +01:00
novlean
c3bb5bd89e
added MWS white paper
Download “9 Things NOT to do when embedding a web server” white paper.
2020-06-24 17:08:35 +01:00
Sergey Lyubka
d22ff2fce7 Really revert 4880069 2020-06-11 19:08:55 +01:00
Sergey Lyubka
fee2980d95 Merge branch 'master' of github.com:cesanta/mongoose 2020-06-11 19:04:45 +01:00
Sergey Lyubka
d6693ed360 Revert 4880069 2020-06-11 19:04:24 +01:00
Sergey Lyubka
4880069775 Fix #1112 2020-06-11 18:38:42 +01:00
Sergey Lyubka
5d217a1262 Merge branch 'dev' of github.com:cesanta/mongoose into dev 2020-06-11 18:29:58 +01:00
Sergey Lyubka
f778d22eac Make it possible to override default FS update algorithm
PUBLISHED_FROM=774a111548da97bd9d195e177b5fb66b0fd66135
2020-06-11 18:27:48 +01:00
Sergey Lyubka
3aa76dcaec Subst CREDPARAMS
PUBLISHED_FROM=545e8dff4ea0bef061c893252c613e3429f56184
2020-06-11 18:27:46 +01:00
Deomid "rojer" Ryabkov
4680573a6b Fixes for -pedantic build mode
PUBLISHED_FROM=d0a15356cf047e579c74869ce3e8fe813752e8c7
2020-05-23 15:55:27 +00:00
Deomid "rojer" Ryabkov
95fcb261eb Fix processing of keep-alive requests when chunks are consumed
PUBLISHED_FROM=136ce2ed4f143d7ee246e5fd1078c431e205bb3a
2020-05-22 23:07:38 +00:00
Sergey Lyubka
5867c67da2 Allow OpenSSL session reuse on 2-way SSL, integrate https://github.com/cesanta/mongoose/pull/877
PUBLISHED_FROM=6e2568b963869d062dd51b590f8e536d043c4ca2
2020-05-22 18:56:31 +00:00
Sergey Lyubka
80d74e9e34 Merge branch 'dev' 2020-05-21 16:45:34 +01:00
Sergey Lyubka
43a0b500f5 6.17 -> 6.18
PUBLISHED_FROM=7893a216b1f7e86e845122eb425e4fed271244b4
2020-05-21 16:42:09 +01:00
Sergey Lyubka
3d53ed17fb Allow OpenSSL session reuse on 2-way SSL, integrate https://github.com/cesanta/mongoose/pull/877
PUBLISHED_FROM=6e2568b963869d062dd51b590f8e536d043c4ca2
2020-05-21 16:17:14 +01:00
Sergey Lyubka
4ea452307e Update certs used for SSL test
PUBLISHED_FROM=2236ecf7fe06bdaf9a89e697b83ff69e1f8c805c
2020-05-21 16:17:12 +01:00
Deomid "rojer" Ryabkov
e61f20f1ed Convert amalgam.py to Python 3
No mongoose.{c,h} diffs

PUBLISHED_FROM=a995a6d6548a914087969e28908f4e8c9ef1d379
2020-05-09 10:48:41 +00:00
Sergey Lyubka
ca11f5ab49 Fix OpenSSL error issue
PUBLISHED_FROM=a3bcdb68f48a4de4a4f55b4399792fdd5211c88d
2020-05-02 11:19:29 +00:00
Sergey Lyubka
000d24d31a Add http proxy client example
PUBLISHED_FROM=443a0d3db63df1b78555a9fa4eff808bef3a9a01
2020-03-25 16:32:49 +00:00
Sergey Lyubka
ef92f2e9c5 Integrate cesanta/dev#1062 - Fix dereferencing in mg_http_free_proto_data_endpoints
PUBLISHED_FROM=47fd1a4de07d2c53c994d29c88ac1d3a7f61c1a0
2020-02-21 14:30:21 +00:00
Sergey Lyubka
4e89eac8dd Integrate cesanta/dev#1074 - Fix typedef bool for MSC
PUBLISHED_FROM=f52fe15edd617d9f1ba2aa4051c116e79671554d
2020-02-21 14:24:50 +00:00