From 2064173f3b789cf78d19e7489bdabe84cb9a94aa Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Fri, 3 Apr 2015 12:10:30 +0200
Subject: util.datamanager: Fix traceback due to %s in log message

---
 util/datamanager.lua | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/datamanager.lua b/util/datamanager.lua
index b82349f1..b4138638 100644
--- a/util/datamanager.lua
+++ b/util/datamanager.lua
@@ -293,7 +293,7 @@ function users(host, store, typ)
 
 	local mode, err = lfs.attributes(store_dir, "mode");
 	if not mode then
-		return function() log("debug", err or (store_dir .. " does not exist")) end
+		return function() log("debug", "%s", err or (store_dir .. " does not exist")) end
 	end
 	local next, state = lfs.dir(store_dir);
 	return function(state)
-- 
cgit v1.2.3


From 38a580bfebacc3c2725f4224c0ca6e7b5c1f8a51 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Sun, 26 Apr 2015 19:50:24 +0200
Subject: net.dns: Make sure argument to math.randomseed does not overflow a 32
 bit *signed* int (blame Lua). Closes #439

---
 net/dns.lua | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/dns.lua b/net/dns.lua
index 28cb4419..763ee9ec 100644
--- a/net/dns.lua
+++ b/net/dns.lua
@@ -225,7 +225,7 @@ end
 
 
 function dns.random(...)    -- - - - - - - - - - - - - - - - - - -  dns.random
-	math.randomseed(math.floor(10000*socket.gettime()) % 0x100000000);
+	math.randomseed(math.floor(10000*socket.gettime()) % 0x80000000);
 	dns.random = math.random;
 	return dns.random(...);
 end
-- 
cgit v1.2.3


From d1a264a39af9e9d29090a8d294cb34d632eff110 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Sat, 2 May 2015 14:41:56 +0200
Subject: util.pposix: Return error from ftruncate if that fails too (but what
 would we do here?)

---
 util-src/pposix.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/util-src/pposix.c b/util-src/pposix.c
index d797f032..5288b08c 100644
--- a/util-src/pposix.c
+++ b/util-src/pposix.c
@@ -750,7 +750,10 @@ int lc_fallocate(lua_State* L) {
 		lua_pushstring(L, strerror(ret));
 		/* posix_fallocate() can leave a bunch of NULs at the end, so we cut that
 		 * this assumes that offset == length of the file */
-		ftruncate(fileno(f), offset);
+		if(ftruncate(fileno(f), offset) != 0) {
+			lua_pushstring(L, strerror(errno));
+			return 3;
+		}
 		return 2;
 	}
 }
-- 
cgit v1.2.3


From 8f40f1f4e63216c60f2f61610a4386376c46c476 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Sat, 2 May 2015 14:52:51 +0200
Subject: util.encodings: Move declarations to top of function [pedantic]

---
 util-src/encodings.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/util-src/encodings.c b/util-src/encodings.c
index 2eaad2c8..c00b2267 100644
--- a/util-src/encodings.c
+++ b/util-src/encodings.c
@@ -476,14 +476,15 @@ static int Lidna_to_unicode(lua_State* L) {	/** idna.to_unicode(s) */
 static int Lidna_to_ascii(lua_State* L) {	/** idna.to_ascii(s) */
 	size_t len;
 	const char* s = check_utf8(L, 1, &len);
+	char* output = NULL;
+	int ret;
 
 	if(s == NULL || len != strlen(s)) {
 		lua_pushnil(L);
 		return 1; /* TODO return error message */
 	}
 
-	char* output = NULL;
-	int ret = idna_to_ascii_8z(s, &output, IDNA_USE_STD3_ASCII_RULES);
+	ret = idna_to_ascii_8z(s, &output, IDNA_USE_STD3_ASCII_RULES);
 
 	if(ret == IDNA_SUCCESS) {
 		lua_pushstring(L, output);
-- 
cgit v1.2.3


From 32707791498b7bb2437753b296f33d8348c06423 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Tue, 5 May 2015 00:41:39 +0200
Subject: util.events: Add local reference to table.remove (fixes traceback)

---
 util/events.lua | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/util/events.lua b/util/events.lua
index 79de1151..81fbc13f 100644
--- a/util/events.lua
+++ b/util/events.lua
@@ -9,6 +9,7 @@
 
 local pairs = pairs;
 local t_insert = table.insert;
+local t_remove = table.remove;
 local t_sort = table.sort;
 local setmetatable = setmetatable;
 local next = next;
@@ -118,7 +119,7 @@ function new()
 		if not w then return; end
 		for i = #w, 1 do
 			if w[i] == wrapper then
-				table.remove(w, i);
+				t_remove(w, i);
 			end
 		end
 		if #w == 0 then
-- 
cgit v1.2.3


From 9699e09082cb84af5e2c74c05d162438a4c6d536 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Tue, 5 May 2015 00:48:55 +0200
Subject: util.statistics: Collect duration sample even if run fewer times than
 the sample interval

---
 util/statistics.lua | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/util/statistics.lua b/util/statistics.lua
index a05a1f91..26355026 100644
--- a/util/statistics.lua
+++ b/util/statistics.lua
@@ -88,7 +88,7 @@ local function new_registry(config)
 
 			return function (value)
 				n_actual_events = n_actual_events + 1;
-				if n_actual_events%duration_sample_interval > 0 then
+				if n_actual_events%duration_sample_interval == 1 then
 					last_event = (last_event%duration_max_samples) + 1;
 					events[last_event] = value;
 				end
@@ -113,7 +113,7 @@ local function new_registry(config)
 
 			return function ()
 				n_actual_events = n_actual_events + 1;
-				if n_actual_events%duration_sample_interval > 0 then
+				if n_actual_events%duration_sample_interval ~= 1 then
 					return nop_function;
 				end
 
-- 
cgit v1.2.3


From 9e2d9737662cc09c8c34f8bc5af9c89c4ebc3d69 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Tue, 5 May 2015 12:21:32 +0200
Subject: mod_pubsub: Add option for default affiliation of non-existent nodes
 (thanks Flow)

---
 plugins/mod_pubsub/mod_pubsub.lua | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua
index de027b58..40c28d27 100644
--- a/plugins/mod_pubsub/mod_pubsub.lua
+++ b/plugins/mod_pubsub/mod_pubsub.lua
@@ -125,11 +125,15 @@ module:hook("host-disco-items", function (event)
 end);
 
 local admin_aff = module:get_option_string("default_admin_affiliation", "owner");
-local function get_affiliation(jid)
+local unowned_aff = module:get_option_string("default_unowned_affiliation");
+local function get_affiliation(jid, node)
 	local bare_jid = jid_bare(jid);
 	if bare_jid == module.host or usermanager.is_admin(bare_jid, module.host) then
 		return admin_aff;
 	end
+	if not node then
+		return unowned_aff;
+	end
 end
 
 function set_service(new_service)
-- 
cgit v1.2.3


From 80bafb72003774e5eb63ef9d3d7960385cfb8c6a Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Wed, 6 May 2015 13:35:34 +0200
Subject: mod_s2s: Fire read timeout event on correct virtualhost for incoming
 connections

---
 plugins/mod_s2s/mod_s2s.lua | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/plugins/mod_s2s/mod_s2s.lua b/plugins/mod_s2s/mod_s2s.lua
index 1ce63a8b..060e04f6 100644
--- a/plugins/mod_s2s/mod_s2s.lua
+++ b/plugins/mod_s2s/mod_s2s.lua
@@ -625,8 +625,9 @@ end
 
 function listener.onreadtimeout(conn)
 	local session = sessions[conn];
+	local host = session.host or session.to_host;
 	if session then
-		return (hosts[session.host] or prosody).events.fire_event("s2s-read-timeout", { session = session });
+		return (hosts[host] or prosody).events.fire_event("s2s-read-timeout", { session = session });
 	end
 end
 
-- 
cgit v1.2.3