Comparison

plugins/mod_admin_telnet.lua @ 9741:d46c376dfe2c

mod_admin_telnet: Validate hostnames in xmpp:ping command Attempt to ping some invalid hostnames cause weird behavior
author Kim Alvefur <zash@zash.se>
date Sat, 29 Dec 2018 03:21:13 +0100
parent 9736:a5ae3f4e1a40
child 9748:99199b53019f
comparison
equal deleted inserted replaced
9740:4b34687ede3f 9741:d46c376dfe2c
1086 def_env.xmpp = {}; 1086 def_env.xmpp = {};
1087 1087
1088 local st = require "util.stanza"; 1088 local st = require "util.stanza";
1089 local new_id = require "util.id".medium; 1089 local new_id = require "util.id".medium;
1090 function def_env.xmpp:ping(localhost, remotehost, timeout) 1090 function def_env.xmpp:ping(localhost, remotehost, timeout)
1091 if not prosody.hosts[localhost] then 1091 localhost = select(2, jid_split(localhost));
1092 return nil, "No such host"; 1092 remotehost = select(2, jid_split(remotehost));
1093 if not localhost then
1094 return nil, "Invalid sender hostname";
1095 elseif not prosody.hosts[localhost] then
1096 return nil, "No such local host";
1097 end
1098 if not remotehost then
1099 return nil, "Invalid destination hostname";
1100 elseif prosody.hosts[remotehost] then
1101 return nil, "Both hosts are local";
1093 end 1102 end
1094 local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()} 1103 local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()}
1095 :tag("ping", {xmlns="urn:xmpp:ping"}); 1104 :tag("ping", {xmlns="urn:xmpp:ping"});
1096 local ret, err; 1105 local ret, err;
1097 local wait, done = async.waiter(); 1106 local wait, done = async.waiter();