From 1bf98a8af7ed3a0538e8547d8c210c26f8253178 Mon Sep 17 00:00:00 2001
From: Andre Noll <maan@tuebingen.mpg.de>
Date: Sat, 19 Mar 2022 23:48:18 +0100
Subject: [PATCH] vss: Reset afhi.chunks_total on eof.

Without this, the server can be crashed by running

	para_client nomore # set the nomore flag
	# wait for eof
	para_client jmp 50 # set the repos flag, clear the next flag
	para_client play # boom

The problem is that the command handler of the jmp command checks
afhi.chunks_total to determine if some audio file is currently
open. Since vss_eof() did not reset chunks_total, the command handler
wrongly believes that there is an open audio file, sets the repos
flag and clears the next flag. When streaming is resumed later, the
virtual streaming system attempts to access the chunk table which
was freed earlier in vss_eof().
---
 vss.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/vss.c b/vss.c
index 9969a150..235219c1 100644
--- a/vss.c
+++ b/vss.c
@@ -845,7 +845,6 @@ static void vss_compute_timeout(struct sched *s, struct vss_task *vsst)
 
 static void vss_eof(struct vss_task *vsst)
 {
-
 	if (!vsst->map)
 		return;
 	if (mmd->new_vss_status_flags & VSS_NOMORE)
@@ -856,8 +855,8 @@ static void vss_eof(struct vss_task *vsst)
 	para_munmap(vsst->map, vsst->mapsize);
 	vsst->map = NULL;
 	mmd->chunks_sent = 0;
-	//mmd->offset = 0;
 	mmd->afd.afhi.seconds_total = 0;
+	mmd->afd.afhi.chunks_total = 0;
 	mmd->afd.afhi.chunk_tv.tv_sec = 0;
 	mmd->afd.afhi.chunk_tv.tv_usec = 0;
 	free(mmd->afd.afhi.chunk_table);
-- 
2.39.5