<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<p>+static enum rtsp_result rtsp_handle(access_t <em>access) { + [… ] + + /</em> Parse header */ + while (!have_header && (in = net_Gets(access, sys->tcp_sock)) != NULL) { + if (strstr(in, “RTSP/1.0”) != NULL) { + rtsp_result = atoi(in + 9);</p>
</blockquote>
<p>The above logic is faulty. I assume the intent is to look for “RTSP/1.0” and then treat the following bytes as the textual-representation of an integer, though this is not what is going on.</p>
<p>If an implementation-specific (or similar) header contains “RTSP/1.0” you would overwrite <code>rtsp_result</code> with a value with what just happens to be at <code>[9, ...)</code> in <code>in</code>, even if a correct value has already been found.</p>
<pre><code>RTSP/1.0 200
Content-Base: ...
Implementation-Specific-Header: RTSP/1.0 korv</code></pre>
<p>The contents of <em>“Implementation-Specific-Header […]”</em> will trigger <code>rtsp_result = atoi( in + 9 )</code>.</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<ul>
<li><pre><code> } else if (strncmp(in, "Content-Base", 12) == 0) {</code></pre></li>
<li><pre><code>     free(sys->content_base);</code></pre></li>
<li><pre><code>     sys->content_base = strdup(in + 14);</code></pre></li>
</ul>
</blockquote>
<p>Nothing in the above says that <code>in + 14</code> is even within the valid range of the string yield by <code>net_Gets</code>; you are really looking for “Content-Base:”, as such usage of <code>strncmp( in, "Content-Base: ", 14 )</code> is far more appropriate.</p>
<p><code>strdup( in + 14 )</code> would then, at most, <code>strdup</code> an empty string.</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<ul>
<li><pre><code> } else if (strncmp(in, "Content-Length", 14) == 0) {</code></pre></li>
<li><pre><code>     content_length = atoi(in + 16);</code></pre></li>
</ul>
</blockquote>
<p>See previous remark.</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<ul>
<li><pre><code> } else if (strncmp("Session:", in, 8) == 0) {</code></pre></li>
<li><pre><code>     parse_session(in, sys->session_id, 64, &sys->keepalive_interval);</code></pre></li>
<li><pre><code> } else if (strncmp("Transport:", in, 10) == 0) {</code></pre></li>
<li><pre><code>     parse_transport(access, in);</code></pre></li>
<li><pre><code> } else if (strncmp("com.ses.streamID:", in, 17) == 0) {</code></pre></li>
<li><pre><code>     sys->stream_id = atoi(in + 17);</code></pre></li>
<li><pre><code> } else if (in[0] == '\0') {</code></pre></li>
<li><pre><code>     have_header = true;</code></pre></li>
<li><pre><code> }</code></pre></li>
</ul>
</blockquote>
<hr style="height:1px;margin-bottom:20px;background-color:#ddd;color:#ddd" />
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<p>+/* Bind two adjacent free ports, of which the first one is even (for RTP data) + * and the second is odd (RTCP). This is a requirement of the satip + * specification <em>/ +static int satip_bind_ports(access_t </em>access) +{ + access_sys_t <em>sys = access->p_sys; + uint8_t rnd; + + vlc_rand_bytes(&rnd, 1); + sys->udp_port = 9000 + (rnd </em> 2); /* randomly chosen, even start point */</p>
</blockquote>
<p>This following loop will, in the worse case, loop forever (given that <code>sys->udp_sock</code> can wrap from <code>65534</code> to <code>0</code> in each of the two <code>sys->udp_port += 2</code>).</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<ul>
<li>while (sys->udp_sock < 0 && sys->udp_port < 65535) {</li>
<li><pre><code> sys->udp_sock = net_OpenDgram(access, "0.0.0.0", sys->udp_port, NULL,</code></pre></li>
<li><pre><code>         0, IPPROTO_UDP);</code></pre></li>
<li><pre><code> if (sys->udp_sock < 0) {</code></pre></li>
<li><pre><code>     sys->udp_port += 2;</code></pre></li>
<li><pre><code>     continue;</code></pre></li>
<li><pre><code> }</code></pre></li>
<li></li>
<li><pre><code> sys->rtcp_sock = net_OpenDgram(access, "0.0.0.0", sys->udp_port + 1, NULL,</code></pre></li>
<li><pre><code>         0, IPPROTO_UDP);</code></pre></li>
<li><pre><code> if (sys->rtcp_sock < 0) {</code></pre></li>
<li><pre><code>     close(sys->udp_sock);</code></pre></li>
<li><pre><code>     sys->udp_port += 2;</code></pre></li>
<li><pre><code>     continue;</code></pre></li>
<li><pre><code> }</code></pre></li>
<li>}</li>
<li></li>
<li>if (sys->udp_sock < 0) {</li>
<li><pre><code> msg_Err(access, "Could not open two adjacent ports for RTP and RTCP data");</code></pre></li>
<li><pre><code> return VLC_EGENERIC;</code></pre></li>
<li>}</li>
<li></li>
<li>return 0; +}</li>
</ul>
</blockquote>