changeset 1296:6959c88c8f13

message about truncated banner
author Matt Johnston <matt@ucc.asn.au>
date Wed, 04 May 2016 15:28:33 +0200
parents 750ec4ec4cbe
children 5abbecdecba4
files cli-auth.c
diffstat 1 files changed, 20 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/cli-auth.c	Wed May 04 15:33:40 2016 +0200
+++ b/cli-auth.c	Wed May 04 15:28:33 2016 +0200
@@ -78,6 +78,7 @@
 	char* banner = NULL;
 	unsigned int bannerlen;
 	unsigned int i, linecount;
+	int truncated = 0;
 
 	TRACE(("enter recv_msg_userauth_banner"))
 	if (ses.authstate.authdone) {
@@ -90,26 +91,29 @@
 
 	if (bannerlen > MAX_BANNER_SIZE) {
 		TRACE(("recv_msg_userauth_banner: bannerlen too long: %d", bannerlen))
-		goto out;
+		truncated = 1;
+	} else {
+		cleantext(banner);
+
+		/* Limit to 24 lines */
+		linecount = 1;
+		for (i = 0; i < bannerlen; i++) {
+			if (banner[i] == '\n') {
+				if (linecount >= MAX_BANNER_LINES) {
+					banner[i] = '\0';
+					truncated = 1;
+					break;
+				}
+				linecount++;
+			}
+		}
+		fprintf(stderr, "%s\n", banner);
 	}
 
-	cleantext(banner);
-
-	/* Limit to 25 lines */
-	linecount = 1;
-	for (i = 0; i < bannerlen; i++) {
-		if (banner[i] == '\n') {
-			if (linecount >= MAX_BANNER_LINES) {
-				banner[i] = '\0';
-				break;
-			}
-			linecount++;
-		}
+	if (truncated) {
+		fprintf(stderr, "[Banner from the server is too long]\n");
 	}
 
-	fprintf(stderr, "%s\n", banner);
-
-out:
 	m_free(banner);
 	TRACE(("leave recv_msg_userauth_banner"))
 }