From: Andre Noll Date: Sat, 7 Apr 2012 22:25:42 +0000 (+0200) Subject: audiod: Check pointers passed to btr_get_node_start(). X-Git-Tag: v0.4.11~19 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=8f5de4b6e1c1299b0d8cf894474cad049f6b0958;p=paraslash.git audiod: Check pointers passed to btr_get_node_start(). If the receiver or writer buffer tree node pointer is NULL, we'll segfault due to a a NULL pointer dereference in btr_get_node_start(). Although this might not be triggerable, it does not hurt to be defensive here. --- diff --git a/audiod.c b/audiod.c index aefac612..40603c4e 100644 --- a/audiod.c +++ b/audiod.c @@ -250,7 +250,7 @@ char *get_time_string(int slot_num) */ length = stat_task->length_seconds; tmp = &stat_task->server_stream_start; - if (s && s->wns) { /* writer active in this slot */ + if (s && s->wns && s->wns[0].btrn) { /* writer active in this slot */ btr_get_node_start(s->wns[0].btrn, &wstime); if (wstime.tv_sec != 0) { /* writer wrote something */ if (s->server_stream_start.tv_sec == 0) { @@ -267,7 +267,7 @@ char *get_time_string(int slot_num) tv_diff(tmp, &stat_task->sa_time_diff, &sss); else tv_add(tmp, &stat_task->sa_time_diff, &sss); - if (!s || !s->wns) { + if (!s || !s->wns || !s->wns[0].btrn) { struct timeval diff; tv_diff(now, &sss, &diff); seconds = diff.tv_sec + stat_task->offset_seconds; @@ -276,11 +276,14 @@ char *get_time_string(int slot_num) tv_diff(now, &wstime, &wtime); //PARA_CRIT_LOG("offset %d\n", s->offset_seconds); seconds = s->offset_seconds; - btr_get_node_start(s->receiver_node->btrn, &rstime); - ret = tv_diff(&rstime, &sss, &rskip); - if (ret > 0) { /* audiod was started in the middle of the stream */ - tv_add(&wtime, &rskip, &sum); - seconds += sum.tv_sec; + if (s->receiver_node->btrn) { + btr_get_node_start(s->receiver_node->btrn, &rstime); + ret = tv_diff(&rstime, &sss, &rskip); + if (ret > 0) { /* audiod was started in the middle of the stream */ + tv_add(&wtime, &rskip, &sum); + seconds += sum.tv_sec; + } else + seconds += wtime.tv_sec; } else seconds += wtime.tv_sec; out: