From: Mike Brady Date: Sat, 26 Oct 2019 09:40:10 +0000 (+0100) Subject: Fix crash when a non-RTSP packet is sent to the session's RTSP port. X-Git-Tag: 3.3.3~2^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eec06397269a2d73458296579444c46c0405f4c0;p=thirdparty%2Fshairport-sync.git Fix crash when a non-RTSP packet is sent to the session's RTSP port. --- diff --git a/rtsp.c b/rtsp.c index ded7035f..b303faa8 100644 --- a/rtsp.c +++ b/rtsp.c @@ -392,8 +392,9 @@ static char *nextline(char *in, int inbuf) { if (*in == '\r') { *in++ = 0; out = in; + inbuf--; } - if (*in == '\n') { + if ((*in == '\n') && (inbuf)) { *in++ = 0; out = in; } @@ -569,13 +570,15 @@ int msg_handle_line(rtsp_message **pmsg, char *line) { } fail: + debug(3,"msg_handle_line fail"); msg_free(pmsg); + *pmsg = NULL; return 0; } enum rtsp_read_request_response rtsp_read_request(rtsp_conn_info *conn, rtsp_message **the_packet) { - *the_packet = NULL; // need this for erro handling + *the_packet = NULL; // need this for error handling enum rtsp_read_request_response reply = rtsp_read_request_response_ok; ssize_t buflen = 4096; @@ -622,6 +625,17 @@ enum rtsp_read_request_response rtsp_read_request(rtsp_conn_info *conn, rtsp_mes reply = rtsp_read_request_response_read_error; goto shutdown; } + +/* // this outputs the message received + { + void *pt = malloc(nread+1); + memset(pt, 0, nread+1); + memcpy(pt, buf + inbuf, nread); + debug(1, "Incoming string on port: \"%s\"",pt); + free(pt); + } +*/ + inbuf += nread; char *next; @@ -629,8 +643,8 @@ enum rtsp_read_request_response rtsp_read_request(rtsp_conn_info *conn, rtsp_mes msg_size = msg_handle_line(the_packet, buf); if (!(*the_packet)) { - warn("no RTSP header received"); - reply = rtsp_read_request_response_bad_packet; + warn("Closing the session because an RTSP header was missing in an incoming packet."); + reply = rtsp_read_request_response_read_error; goto shutdown; }