shithub: riscv

Download patch

ref: a029cb11d3d19b4064aa0c739707cd4b36742887
parent: 74f9483f1b08becb7bd690515ecd706752f06a3d
author: Alex Musolino <alex@musolino.id.au>
date: Sat Jun 3 22:08:39 EDT 2023

fix up auth/*2* programs to report write errors

--- a/sys/src/cmd/auth/asn12rsa.c
+++ b/sys/src/cmd/auth/asn12rsa.c
@@ -72,6 +72,7 @@
 	}
 	if(s == nil)
 		sysfatal("smprint: %r");
-	write(1, s, strlen(s));
+	if(write(1, s, strlen(s)) != strlen(s))
+		sysfatal("write: %r");
 	exits(0);
 }
--- a/sys/src/cmd/auth/rsa2csr.c
+++ b/sys/src/cmd/auth/rsa2csr.c
@@ -38,6 +38,7 @@
 	if(cert == nil)
 		sysfatal("X509rsareq: %r");
 
-	write(1, cert, len);
+	if(write(1, cert, len) != len)
+		sysfatal("write: %r");
 	exits(0);
 }
--- a/sys/src/cmd/auth/rsa2jwk.c
+++ b/sys/src/cmd/auth/rsa2jwk.c
@@ -46,7 +46,7 @@
 main(int argc, char **argv)
 {
 	uchar nbuf[8192], ebuf[512];
-	char *nstr, *estr;
+	char *nstr, *estr, *s;
 	RSApriv *k;
 	int nlen, elen;
 
@@ -76,7 +76,7 @@
 	mptobe(k->pub.ek, ebuf, elen, nil);
 	estr = encurl64(ebuf, elen);
 
-	print(
+	s = smprint(
 		"{"
 		"\"kty\": \"RSA\","
 		"\"n\": \"%s\","
@@ -83,5 +83,9 @@
 		"\"e\": \"%s\""
 		"}\n",
 		nstr, estr);
+	if(s == nil)
+		sysfatal("smprint: %r");
+	if(write(1, s, strlen(s))  != strlen(s))
+		sysfatal("write: %r");
 	exits(nil);
 }
--- a/sys/src/cmd/auth/rsa2ssh.c
+++ b/sys/src/cmd/auth/rsa2ssh.c
@@ -16,7 +16,7 @@
 main(int argc, char **argv)
 {
 	RSApriv *k;
-	char *comment;
+	char *comment, *s;
 	uchar buf[8192], *p;
 
 	fmtinstall('B', mpfmt);
@@ -46,7 +46,11 @@
 	p = putmp2(p, k->pub.ek);
 	p = putmp2(p, k->pub.n);
 
-	print("ssh-rsa %.*[ %s\n", (int)(p-buf), buf, comment);
+	s = smprint("ssh-rsa %.*[ %s\n", (int)(p-buf), buf, comment);
+	if(s == nil)
+		sysfatal("smprint: %r");
+	if(write(1, s, strlen(s)) != strlen(s))
+		sysfatal("write: %r");
 
 	exits(nil);
 }
--- a/sys/src/cmd/auth/ssh2rsa.c
+++ b/sys/src/cmd/auth/ssh2rsa.c
@@ -161,6 +161,7 @@
 {
 	int fd;
 	RSApriv *p;
+	char *s;
 	uchar buf[64];
 
 	fd = 0;
@@ -189,11 +190,15 @@
 	if((p = fill()) == nil)
 		sysfatal("fill: %r");
 
-	print("%s size=%d ek=%B !dk=%B n=%B !p=%B !q=%B !kp=%B !kq=%B !c2=%B\n",
+	s = smprint("%s size=%d ek=%B !dk=%B n=%B !p=%B !q=%B !kp=%B !kq=%B !c2=%B\n",
 		"key service=ssh proto=rsa",
 		mpsignif(p->pub.n), p->pub.ek,
 		p->dk, p->pub.n, p->p, p->q,
 		p->kp, p->kq, p->c2);
+	if(s == nil)
+		sysfatal("smprint: %r");
+	if(write(1, s, strlen(s)) != strlen(s))
+		sysfatal("write: %r");
 
 	exits(nil);
 }
--- a/sys/src/cmd/auth/x5092pub.c
+++ b/sys/src/cmd/auth/x5092pub.c
@@ -20,6 +20,7 @@
 main(int argc, char **argv)
 {
 	int tot, n;
+	char *s;
 	uchar *buf;
 	RSApub *pub;
 
@@ -58,6 +59,10 @@
 		pub = X509toRSApub(buf, tot, subject, sizeof(subject));
 	if(pub == nil)
 		sysfatal("X509toRSApub: %r");
-	print("key proto=rsa size=%d ek=%B n=%B subject=%q \n", mpsignif(pub->n), pub->ek, pub->n, subject);
+	s = smprint("key proto=rsa size=%d ek=%B n=%B subject=%q \n", mpsignif(pub->n), pub->ek, pub->n, subject);
+	if(s == nil)
+		sysfatal("smprint: %r");
+	if(write(1, s, strlen(s)) != strlen(s))
+		sysfatal("write: %r");
 	exits(nil);
 }