meetecho / janus-gateway

Janus WebRTC Server
https://janus.conf.meetecho.com
GNU General Public License v3.0
8.15k stars 2.47k forks source link

Invalid ICE address displays error messages from libnice #1973

Closed mp16 closed 4 years ago

mp16 commented 4 years ago

I have crafted an invalid ICE candidate (IP "99192.168.3.12"):

Mar 02 15:39:08 [Mon Mar  2 15:39:08 2020] {"candidate":{"candidate":"candidate:2895048534 1 udp 2122260223 99192.168.3.12 23128 typ host generation 0 ufrag lpF3 network-id 1","sdpMLineIndex":0,"sdpMid":"audio"},"handle_id":7528623161552875,"session_id":2146165875570853,"transaction":"QvoFVvL7T1SX","janus":"trickle"}
Mar 02 15:39:08 [Mon Mar  2 15:39:08 2020] [WSS-0x7f42b0005fa0] Done, parsing message: 279 bytes
Mar 02 15:39:08 [Mon Mar  2 15:39:08 2020] Got a Janus API request from janus.transport.websockets (0x7f42b0005e70)
Mar 02 15:39:08 [Mon Mar  2 15:39:08 2020] [7528623161552875] Trickle candidate (audio): candidate:2895048534 1 udp 2122260223 99192.168.3.12 23128 typ host generation 0 ufrag lpF3 network-id 1
Mar 02 15:39:08 [Mon Mar  2 15:39:08 2020] [7528623161552875]  Adding remote candidate component:1 stream:1 type:host 99192.168.3.12:23128
Mar 02 15:39:08 [Mon Mar  2 15:39:08 2020] [7528623161552875]  Transport: UDP
Mar 02 15:39:08 (process:1288): libnice-CRITICAL **: file address.c: line 147 (nice_address_set_port): should not be reached
Mar 02 15:39:08 [Mon Mar  2 15:39:08 2020] [7528623161552875]    Candidate added to the list! (1 elements for 1/1)
Mar 02 15:39:08 [Mon Mar  2 15:39:08 2020] [7528623161552875] ICE already started for this component, setting candidates we have up to now
Mar 02 15:39:08 [Mon Mar  2 15:39:08 2020] [7528623161552875] ## Setting remote candidates: stream 1, component 1 (1 in the list)
Mar 02 15:39:09 [Mon Mar  2 15:39:08 2020] [7528623161552875] >> Remote Stream #1, Component #1
Mar 02 15:39:09 (process:1288): libnice-CRITICAL **: file address.c: line 249 (nice_address_to_string): should not be reached
Mar 02 15:39:09 (process:1288): libnice-CRITICAL **: file address.c: line 165 (nice_address_get_port): should not be reached

There is several error messages rated as "critical" by libnice.

The error comes from the result of nice_address_set_from_string that is not checked. https://github.com/meetecho/janus-gateway/blob/2d3c53e8a874c5717126af7319c19c64ae3854a0/sdp.c#L787 https://github.com/meetecho/janus-gateway/blob/2d3c53e8a874c5717126af7319c19c64ae3854a0/sdp.c#L792

If nice_address_set_from_string fails (the IP is invalid), I suggest to have a specific log message (level LOG_ERR maybe).

lminiero commented 4 years ago

Can you share an IP that causes that error?

Edit: sorry, just saw you shared one above, thanks!

lminiero commented 4 years ago

Should be fixed now.

mp16 commented 4 years ago

Sorry, it is not ok, I just got the error again with the version 02399ce75c8b47a0bdc8b65359652b4f67a57f13.

(process:25210): libnice-CRITICAL **: file address.c: line 147 (nice_address_set_port): should not be reached

(gdb) bt
#0  0x00007ffff746cafb in g_logv () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#1  0x00007ffff746cc6f in g_log () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#2  0x000000000046bf5d in janus_sdp_parse_candidate (ice_stream=ice_stream@entry=0x7ffdf407ed90,
    candidate=candidate@entry=0x7ffeea7eb670 "remote2 1 udp 1853827327 2a01:cb05:87e2:5c00:b9e0:b4ac:66d8:2dc6 49410 typ prflx raddr 2a01:cb05:87", trickle=trickle@entry=1) at sdp.c:799
#3  0x0000000000423769 in janus_ice_cb_new_remote_candidate (agent=<optimized out>, candidate=0x7ffe7c004000, ice=0x7fffd402f680) at ice.c:2148
#4  0x00007ffff773cfa5 in g_closure_invoke () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#5  0x00007ffff774efc1 in ?? () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#6  0x00007ffff7756d41 in g_signal_emitv () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#7  0x00007ffff798d6ef in ?? () from /usr/lib/x86_64-linux-gnu/libnice.so.10
#8  0x00007ffff79964c8 in ?? () from /usr/lib/x86_64-linux-gnu/libnice.so.10
#9  0x00007ffff5188911 in ?? () from /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0
#10 0x00007ffff746604a in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#11 0x00007ffff74663f0 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#12 0x00007ffff7466712 in g_main_loop_run () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#13 0x000000000042e837 in janus_ice_handle_thread (data=0x7fffd402f680) at ice.c:1118
#14 0x00007ffff748cc55 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#15 0x00007ffff5da26ba in start_thread (arg=0x7ffeea7fc700) at pthread_create.c:333
#16 0x00007ffff5ad841d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

See https://pastebin.com/PPymV0yM for full backtrace.

I think that nice_address_set_port must be called only if added is true.

Thank you.

atoppi commented 4 years ago

Hi @mp16, to get a better stack trace please compile libnice (at least v0.1.16) with the same debugging flags you used for Janus.

mp16 commented 4 years ago

Hello,

Okay, I will do that next week.