From a649af9e027b2f36f7d6c288586a5a86c01499ee Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Fri, 18 Dec 2020 22:29:44 +0100
Subject: mod_component: Distinguish missing stream @to from unknown local
 component (thanks Daniel_W)

Spectrum2 did not include a stream @to attribute due to a configuration
error.  "nil does not match ..." is not very clear in pointing this out
and is somewhat confusing, tho it did help pinpoint what went wrong.

It's also not great leak to programming language internals like "nil"
out into user-facing strings like this.
---
 plugins/mod_component.lua | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/plugins/mod_component.lua b/plugins/mod_component.lua
index d06df71c..a0bac298 100644
--- a/plugins/mod_component.lua
+++ b/plugins/mod_component.lua
@@ -193,6 +193,10 @@ function stream_callbacks.error(session, error, data)
 end
 
 function stream_callbacks.streamopened(session, attr)
+	if not attr.to then
+		session:close{ condition = "improper-addressing", text = "A 'to' attribute is required on stream headers" };
+		return;
+	end
 	if not hosts[attr.to] or not hosts[attr.to].modules.component then
 		session:close{ condition = "host-unknown", text = tostring(attr.to).." does not match any configured external components" };
 		return;
-- 
cgit v1.2.3