shithub: cuefs

Download patch

ref: 4d831d85510eebd10ea8fb93e3f116a7f71c3362
parent: 34b8565a804d8f43da7a22eba580300a9b5db4e6
author: Tevo <[email protected]>
date: Sun Dec 27 14:11:19 EST 2020

Fix buffer overflow causing crash on unmount

--- a/BUGS
+++ b/BUGS
@@ -1,5 +1,4 @@
 • unsure if seeking on a file works correctly
-• sometimes crashes on unmount (buffer overflow caught by free())
 • current treatment of lossy sources is less than ideal
 • can only serve .wav and raw pcm files (no flac encoder)
 • everything will get resampled to 44100kHz/16bit/2channel
--- a/cue.c
+++ b/cue.c
@@ -187,7 +187,7 @@
 void
 settimestamp(Cuesheet *c, int i, Timestamp t)
 {
-	Start *entry, *before;
+	Start *entry, **p;
 
 	if(c->curentry == nil)
 		parserfatal("timestamp outside of track");
@@ -198,17 +198,15 @@
 	entry->Timestamp = t;
 	entry->index = i;
 
-	before = nil;
+	p = &c->curentry->starts;
 
-	if(c->curentry->starts == nil)
-		c->curentry->starts = entry;
-	else
+	while((*p) && (*p)->index < i)
 	{
-		for(Start *s = c->curentry->starts; s != nil && s->index < i; s++)
-			before = s;
-		entry->next = before->next;
-		before->next = entry;
+		p = &(*p)->next;
 	}
+
+	entry->next = *p;
+	*p = entry;
 }
 
 char*