shithub: rtmp

Download patch

ref: dad1582627ca77f86f0a6c64d9503a36cab8f00c
parent: 89e5bd16ebd6946456bc737a2c0b2796f125a5a7
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Jul 29 09:36:57 EDT 2021

amf: make sure type is set when parsing

--- a/amf0.c
+++ b/amf0.c
@@ -250,11 +250,11 @@
 	int n;
 	Amf0 *a;
 
+	*amf0 = nil;
 	atleast("type", 1);
+	a = ecalloc(1, sizeof(*a));
+	a->type = -1;
 
-	a = ecalloc(1, sizeof(Amf0));
-	*amf0 = nil;
-
 	switch(*p++){
 	case Anull:
 		a->type = Tnull;
@@ -263,13 +263,13 @@
 		atleast("num", 8);
 		for(n = 0, x.u = 0; n < 8; n++)
 			x.u = x.u<<8 | *p++;
-		a->type = Tnum;
 		a->num = x.v;
+		a->type = Tnum;
 		break;
 	case Abool:
 		atleast("bool", 1);
-		a->type = Tbool;
 		a->bool = *p++;
+		a->type = Tbool;
 		break;
 	case Alstr:
 		if((p = amf0i32get(p, e, &n)) == nil)
@@ -283,10 +283,10 @@
 		atleast("str", n);
 		a->str = estrndup(p, n);
 		p += n;
+		a->type = Tstr;
 		break;
 	case Aobj:
 		atleast("obj", 3); /* Aend should be there anyway */
-		a->type = Tobj;
 		for(a->obj.n = 0;;){
 			if((p = amf0i16get(p, e, &s16)) == nil)
 				break;
@@ -312,9 +312,9 @@
 				break;
 			}
 		}
+		a->type = Tobj;
 		break;
 	case Aarr:
-		a->type = Tarr;
 		if((p = amf0i32get(p, e, &a->arr.n)) == nil)
 			break;
 		a->arr.v = emalloc(sizeof(*a->arr.v)*a->arr.n);
@@ -328,10 +328,11 @@
 			p = nil;
 			werrstr("array doesn't end with Aend");
 		}
+		a->type = Tarr;
 		break;
 	case Aend:
-		p = nil;
 		werrstr("unexpected Aend");
+		p = nil;
 		break;
 	default:
 		werrstr("unexpected type %d", p[-1]);
--- a/amf0.h
+++ b/amf0.h
@@ -1,10 +1,10 @@
 enum {
+	Tnull,
 	Tstr,
 	Tnum,
 	Tbool,
 	Tarr,
 	Tobj,
-	Tnull,
 };
 
 typedef struct Amf0 Amf0;