From 501e349466df8bf483e873af0d4dcfd6b43fb980 Mon Sep 17 00:00:00 2001 From: Mike Brady Date: Mon, 12 Nov 2018 16:41:29 +0000 Subject: [PATCH 1/5] Add better error handling if a reply header message is faulty. --- rtsp.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/rtsp.c b/rtsp.c index ab097a74..4446d806 100644 --- a/rtsp.c +++ b/rtsp.c @@ -648,7 +648,7 @@ shutdown: return reply; } -void msg_write_response(int fd, rtsp_message *resp) { +int msg_write_response(int fd, rtsp_message *resp) { char pkt[2048]; int pktfree = sizeof(pkt); char *p = pkt; @@ -666,8 +666,10 @@ void msg_write_response(int fd, rtsp_message *resp) { n = snprintf(p, pktfree, "%s: %s\r\n", resp->name[i], resp->value[i]); pktfree -= n; p += n; - if (pktfree <= 1024) - die("Attempted to write overlong RTSP packet 1"); + if (pktfree <= 1024) { + debug(1,"Attempted to write overlong RTSP packet 1"); + return -1; + } } // Here, if there's content, write the Content-Length header ... @@ -677,8 +679,10 @@ void msg_write_response(int fd, rtsp_message *resp) { n = snprintf(p, pktfree, "Content-Length: %d\r\n", resp->contentlength); pktfree -= n; p += n; - if (pktfree <= 1024) - die("Attempted to write overlong RTSP packet 2"); + if (pktfree <= 1024) { + debug(1,"Attempted to write overlong RTSP packet 2"); + return -2; + } debug(1, "Content is \"%s\"", resp->content); memcpy(p, resp->content, resp->contentlength); pktfree -= resp->contentlength; @@ -689,11 +693,15 @@ void msg_write_response(int fd, rtsp_message *resp) { pktfree -= n; p += n; - if (pktfree <= 1024) - die("Attempted to write overlong RTSP packet 3"); - - if (write(fd, pkt, p - pkt) != p - pkt) + if (pktfree <= 1024) { + debug(1,"Attempted to write overlong RTSP packet 3"); + return -3; + } + if (write(fd, pkt, p - pkt) != p - pkt) { debug(1, "Error writing an RTSP packet -- requested bytes not fully written."); + return -4; + } + return 0; } void handle_record(rtsp_conn_info *conn, rtsp_message *req, rtsp_message *resp) { @@ -2069,7 +2077,12 @@ static void *rtsp_conversation_thread_func(void *pconn) { } while (conn->stop == 0 && pselect(conn->fd + 1, NULL, &writefds, NULL, NULL, &pselect_sigset) <= 0); if (conn->stop == 0) { - msg_write_response(conn->fd, resp); + int err = msg_write_response(conn->fd, resp); + if (err) { + debug(1,"A communication error was detected. Closing the play session."); + conn->stop = 1; + pthread_cancel(conn->thread); + } } pthread_cleanup_pop(1); pthread_cleanup_pop(1); From 67083665adf3adf6c5fdf66a74ef1230a7dd451a Mon Sep 17 00:00:00 2001 From: Mike Brady Date: Tue, 13 Nov 2018 11:00:05 +0000 Subject: [PATCH 2/5] Get more diagnostic messages when a TuneBlade-induced error occurs. --- player.c | 1 + rtsp.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/player.c b/player.c index 43461bf3..803288e6 100644 --- a/player.c +++ b/player.c @@ -2777,6 +2777,7 @@ int player_stop(rtsp_conn_info *conn) { if (conn->player_thread) { debug(2, "player_thread cancel..."); pthread_cancel(*conn->player_thread); + debug(2, "player_thread join..."); pthread_join(*conn->player_thread, NULL); debug(2, "player_thread joined."); free(conn->player_thread); diff --git a/rtsp.c b/rtsp.c index 4446d806..adb2dc50 100644 --- a/rtsp.c +++ b/rtsp.c @@ -2079,9 +2079,11 @@ static void *rtsp_conversation_thread_func(void *pconn) { if (conn->stop == 0) { int err = msg_write_response(conn->fd, resp); if (err) { + int odv = debuglev; + debuglev = 3; debug(1,"A communication error was detected. Closing the play session."); - conn->stop = 1; - pthread_cancel(conn->thread); + player_stop(conn); + debuglev = odv; } } pthread_cleanup_pop(1); From 29a37f44b9fbdfd2e8ba26c5cee1e02ddb292649 Mon Sep 17 00:00:00 2001 From: Mike Brady Date: Wed, 14 Nov 2018 12:25:56 +0000 Subject: [PATCH 3/5] Check timer values a bit more carefully and ignore crazy values. --- rtp.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/rtp.c b/rtp.c index 35b2a2bc..4d13199c 100644 --- a/rtp.c +++ b/rtp.c @@ -621,9 +621,14 @@ void *rtp_timing_receiver(void *arg) { distant_transmit_time = (uint64_t)nctohl(&packet[24]) << 32; distant_transmit_time += nctohl(&packet[28]); - - uint64_t remote_processing_time = distant_transmit_time - distant_receive_time; - + + uint64_t remote_processing_time = 0; + + if (distant_transmit_time >= distant_receive_time) + remote_processing_time = distant_transmit_time - distant_receive_time; + else { + debug(1, "Yikes: distant_transmit_time is before distant_receive_time; remote processing time set to zero."); + } // debug(1,"Return trip time: %" PRIu64 " uS, remote processing time: %" PRIu64 " // uS.",(return_time*1000000)>>32,(remote_processing_time*1000000)>>32); @@ -632,10 +637,10 @@ void *rtp_timing_receiver(void *arg) { // remove the remote processing time from the record of the return time, as long at the // processing time looks sensible. - if ((remote_processing_time > 0) && (remote_processing_time < return_time)) + if (remote_processing_time < return_time) return_time -= remote_processing_time; else - debug(1, "Non-sensical remote processing time -- ignored."); + debug(1, "Remote processing time greater than return time -- ignored."); int cc; for (cc = time_ping_history - 1; cc > 0; cc--) { From 99374ac11313d4d4798c99ec0ace140cfa662d68 Mon Sep 17 00:00:00 2001 From: Mike Brady Date: Wed, 14 Nov 2018 17:21:30 +0000 Subject: [PATCH 4/5] Add a little diagnostic to see what's in the POST message.: --- rtsp.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/rtsp.c b/rtsp.c index adb2dc50..73d8d05a 100644 --- a/rtsp.c +++ b/rtsp.c @@ -2063,9 +2063,28 @@ static void *rtsp_conversation_thread_func(void *pconn) { break; } } - if (method_selected == 0) + if (method_selected == 0) { debug(1, "RTSP thread %d: Unrecognised and unhandled rtsp request \"%s\".", conn->connection_number, req->method); + + + int y = req->contentlength; + if (y > 0) { + char obf[4096]; + if (y > 4096) + y = 4096; + char *p = req->content; + char *obfp = obf; + int obfc; + for (obfc = 0; obfc < y; obfc++) { + snprintf(obfp, 3, "%02X", (unsigned int)p); + p++; + obfp += 2; + }; + *obfp = 0; + debug(1, "Content: \"%s\".",obf); + } + } } debug(debug_level, "RTSP thread %d: RTSP Response:", conn->connection_number); debug_print_msg_headers(debug_level, resp); From ca3c05f8b53c767d7de088bc976e69631a989b9f Mon Sep 17 00:00:00 2001 From: Mike Brady Date: Wed, 14 Nov 2018 17:31:39 +0000 Subject: [PATCH 5/5] Fix silly issue with diagnostic code. --- rtsp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtsp.c b/rtsp.c index 73d8d05a..4663470a 100644 --- a/rtsp.c +++ b/rtsp.c @@ -2077,7 +2077,7 @@ static void *rtsp_conversation_thread_func(void *pconn) { char *obfp = obf; int obfc; for (obfc = 0; obfc < y; obfc++) { - snprintf(obfp, 3, "%02X", (unsigned int)p); + snprintf(obfp, 3, "%02X", (unsigned int)*p); p++; obfp += 2; };