shithub: riscv

Download patch

ref: 19c89f5212bf073baf999fd3320cfe7ffe915f70
parent: 6940bbc50beffcd7912abfc8756936add39183bb
author: cinap_lenrek <[email protected]>
date: Fri Jan 6 16:16:21 EST 2023

libauthsrv: import better passtodeskey() function (from drawterm)

--- a/sys/src/libauthsrv/passtokey.c
+++ b/sys/src/libauthsrv/passtokey.c
@@ -9,14 +9,14 @@
 	uchar buf[PASSWDLEN], *t;
 	int i, n;
 
-	n = strlen(p);
-	if(n >= PASSWDLEN)
-		n = PASSWDLEN-1;
 	memset(buf, ' ', 8);
-	t = buf;
-	strncpy((char*)t, p, n);
-	t[n] = 0;
+	n = strlen(p);
+	if(n >= sizeof(buf))
+		n = sizeof(buf)-1;
+	memmove(buf, p, n);
+	buf[n] = 0;
 	memset(key, 0, DESKEYLEN);
+	t = buf;
 	for(;;){
 		for(i = 0; i < DESKEYLEN; i++)
 			key[i] = (t[i] >> i) + (t[i+1] << (8 - (i+1)));