changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: ssh: don't assume error messages are ASCII. format number of complete runes, not bytes.

changeset 7038: ba424de99a20
parent 7037: 5e221ac3a3f6
child 7039: 32d099aa68a6
author: cinap_lenrek@felloff.net
date: Mon, 25 Feb 2019 01:19:44 +0100
files: sys/src/cmd/ssh.c
description: ssh: don't assume error messages are ASCII. format number of complete runes, not bytes.
     1.1--- a/sys/src/cmd/ssh.c
     1.2+++ b/sys/src/cmd/ssh.c
     1.3@@ -544,7 +544,7 @@ kex(int gotkexinit)
     1.4 		for(t=tab; *t != nil; t++){
     1.5 			if(unpack(p, recv.w-p, "s.", &s, &n, &p) < 0)
     1.6 				break;
     1.7-			fprint(2, "%s: %.*s\n", *t, n, s);
     1.8+			fprint(2, "%s: %.*s\n", *t, utfnlen(s, n), s);
     1.9 		}
    1.10 	}
    1.11 
    1.12@@ -661,7 +661,7 @@ authfailure(char *meth)
    1.13 	if(unpack(recv.r, recv.w-recv.r, "_sb", &s, &n, &partial) < 0)
    1.14 		sysfatal("bad auth failure response");
    1.15 	free(authnext);
    1.16-	authnext = smprint("%.*s", n, s);
    1.17+	authnext = smprint("%.*s", utfnlen(s, n), s);
    1.18 if(debug)
    1.19 	fprint(2, "userauth %s failed: partial=%d, next=%s\n", meth, partial, authnext);
    1.20 	return partial != 0 || !authok(meth);
    1.21@@ -903,9 +903,9 @@ Retry:
    1.22 		m--;
    1.23 
    1.24 	if(n > 0)
    1.25-		fprint(fd, "%.*s\n", n, name);
    1.26+		fprint(fd, "%.*s\n", utfnlen(name, n), name);
    1.27 	if(m > 0)
    1.28-		fprint(fd, "%.*s\n", m, inst);
    1.29+		fprint(fd, "%.*s\n", utfnlen(inst, m), inst);
    1.30 
    1.31 	/* lang, nprompt */
    1.32 	if(unpack(recv.r, recv.w-recv.r, "su.", &s, &n, &nquest, &recv.r) < 0)
    1.33@@ -966,19 +966,21 @@ dispatch(void)
    1.34 		if(unpack(recv.r, recv.w-recv.r, "_sb", &s, &n, &b) < 0)
    1.35 			break;
    1.36 		if(debug)
    1.37-			fprint(2, "%s: global request: %.*s\n", argv0, n, s);
    1.38+			fprint(2, "%s: global request: %.*s\n",
    1.39+				argv0, utfnlen(s, n), s);
    1.40 		if(b != 0)
    1.41 			sendpkt("b", MSG_REQUEST_FAILURE);
    1.42 		return;
    1.43 	case MSG_DISCONNECT:
    1.44 		if(unpack(recv.r, recv.w-recv.r, "_us", &c, &s, &n) < 0)
    1.45 			break;
    1.46-		sysfatal("disconnect: (%d) %.*s", c, n, s);
    1.47+		sysfatal("disconnect: (%d) %.*s", c, utfnlen(s, n), s);
    1.48 		return;
    1.49 	case MSG_DEBUG:
    1.50 		if(unpack(recv.r, recv.w-recv.r, "__sb", &s, &n, &c) < 0)
    1.51 			break;
    1.52-		if(c != 0 || debug) fprint(2, "%s: %.*s\n", argv0, n, s);
    1.53+		if(c != 0 || debug)
    1.54+			fprint(2, "%s: %.*s\n", argv0, utfnlen(s, n), s);
    1.55 		return;
    1.56 	case MSG_USERAUTH_BANNER:
    1.57 		if(unpack(recv.r, recv.w-recv.r, "_s", &s, &n) < 0)
    1.58@@ -1025,7 +1027,7 @@ dispatch(void)
    1.59 			if(unpack(p, recv.w-p, "s", &s, &n) < 0)
    1.60 				break;
    1.61 			if(n != 0 && status == nil)
    1.62-				status = smprint("%.*s", n, s);
    1.63+				status = smprint("%.*s", utfnlen(s, n), s);
    1.64 			c = MSG_CHANNEL_SUCCESS;
    1.65 		} else if(n == 11 && memcmp(s, "exit-status", n) == 0){
    1.66 			if(unpack(p, recv.w-p, "u", &n) < 0)
    1.67@@ -1035,7 +1037,8 @@ dispatch(void)
    1.68 			c = MSG_CHANNEL_SUCCESS;
    1.69 		} else {
    1.70 			if(debug)
    1.71-				fprint(2, "%s: channel request: %.*s\n", argv0, n, s);
    1.72+				fprint(2, "%s: channel request: %.*s\n",
    1.73+					argv0, utfnlen(s, n), s);
    1.74 			c = MSG_CHANNEL_FAILURE;
    1.75 		}
    1.76 		if(b != 0)
    1.77@@ -1270,7 +1273,7 @@ Next1:	switch(recvpkt()){
    1.78 	case MSG_CHANNEL_OPEN_FAILURE:
    1.79 		if(unpack(recv.r, recv.w-recv.r, "_uus", &c, &b, &s, &n) < 0)
    1.80 			n = strlen(s = "???");
    1.81-		sysfatal("channel open failure: (%d) %.*s", b, n, s);
    1.82+		sysfatal("channel open failure: (%d) %.*s", b, utfnlen(s, n), s);
    1.83 	case MSG_CHANNEL_OPEN_CONFIRMATION:
    1.84 		break;
    1.85 	}