shithub: zuke

Download patch

ref: 283868a78a5ecaadebd697505034e9094322621b
parent: 3aea7228518a7808c70e083f5ca0d509edf41aa8
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Oct 12 08:53:04 EDT 2020

icy: make sure we have bytes to parse in the first place

--- a/icy.c
+++ b/icy.c
@@ -18,23 +18,24 @@
 		return -1;
 	fprint(f, "GET /%s HTTP/0.9\r\nIcy-MetaData: 1\r\n\r\n", e ? e : "");
 	s0 = malloc(4096);
-	n = readn(f, s0, 4095);
-	s0[n] = 0;
-	for(s = s0; s = strchr(s, '\n');){
-		s++;
-		if(strncmp(s, "icy-name:", 9) == 0 && (e = strchr(s, '\r')) != nil){
-			*e = 0;
-			m->artist[0] = strdup(s+9);
-			m->numartist = 1;
-			s = e+1;
-		}else if(strncmp(s, "icy-url:", 8) == 0 && (e = strchr(s, '\r')) != nil){
-			*e = 0;
-			m->title = strdup(s+8);
-			s = e+1;
+	if((n = readn(f, s0, 4095)) > 0){
+		s0[n] = 0;
+		for(s = s0; s = strchr(s, '\n');){
+			s++;
+			if(strncmp(s, "icy-name:", 9) == 0 && (e = strchr(s, '\r')) != nil){
+				*e = 0;
+				m->artist[0] = strdup(s+9);
+				m->numartist = 1;
+				s = e+1;
+			}else if(strncmp(s, "icy-url:", 8) == 0 && (e = strchr(s, '\r')) != nil){
+				*e = 0;
+				m->title = strdup(s+8);
+				s = e+1;
+			}
 		}
 	}
 	free(s0);
 	close(f);
 
-	return 0;
+	return n > 0 ? 0 : -1;
 }