From a7468eaa3752118744bc4a0e23be8bef176b29dd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net>
Date: Sat, 9 Apr 2022 15:13:02 -0400
Subject: [PATCH] Throw more interesting errors when a continuation line read
 fails

---
 exec/imapservice.js | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/exec/imapservice.js b/exec/imapservice.js
index a79f55e8e4..354231ce10 100644
--- a/exec/imapservice.js
+++ b/exec/imapservice.js
@@ -649,7 +649,7 @@ function handle_command(command, args, defs)
 function parse_command(line)
 {
 	function execute_line(args) {
-		if(args.length >= 2 && typeof(args[1]) == 'string') {
+		if(args.length >= 2) {
 			command=args[1].toUpperCase();
 			args.splice(1,1);
 			if(handle_command(command, args, any_state_command_handlers))
@@ -714,6 +714,10 @@ function parse_command(line)
 			var len = parseInt(line);
 			if(len) {
 				ret=client.socket.recv(len);
+				if (ret === null)
+					throw new Error('recv() of ' + len + ' bytes returned null');
+				if (ret.length !== len)
+					throw new Error('recv() of ' + len + ' bytes returned a string with ' + ret.length + ' instead.');
 				line=client.socket.recvline(10240, 1800);
 			}
 			else {
-- 
GitLab