diff --git a/svr-authpubkey.c b/svr-authpubkey.c
index 04d1b139cb21da2757a84e4f2c57985089ace755..fbee63f0bb5c868172e1b29c3dfe9349c8b025a9 100644
--- a/svr-authpubkey.c
+++ b/svr-authpubkey.c
@@ -195,9 +195,9 @@ static int checkpubkey_line(buffer* line, int line_num, char* filename,
 	unsigned int pos, len;
 	int ret = DROPBEAR_FAILURE;
 
-	if (line->len < MIN_AUTHKEYS_LINE) {
-		TRACE(("checkpubkey: line too short"))
-		return DROPBEAR_FAILURE; /* line is too short for it to be a valid key */
+	if (line->len < MIN_AUTHKEYS_LINE || line->len > MAX_AUTHKEYS_LINE) {
+		TRACE(("checkpubkey: bad line length %d", line->len))
+		return DROPBEAR_FAILURE;
 	}
 
 	/* compare the algorithm. +3 so we have enough bytes to read a space and some base64 characters too. */