ref: e437b1b289354c9d390b400f1c9c215857848126
parent: 757354dac6d55d12f28a3a94c601e625cf89c5ac
author: cinap_lenrek <[email protected]>
date: Thu Mar 12 13:44:33 EDT 2015
pemencode: handle base64 input length < 3, fix bogus zero termination
--- a/sys/src/cmd/auth/pemencode.c
+++ b/sys/src/cmd/auth/pemencode.c
@@ -48,11 +48,11 @@
break;
tot += n;
}
- buf[tot] = 0;
- cbuf = malloc(2*tot);
+ len = 2*tot+3;
+ cbuf = malloc(len);
if(cbuf == nil)
sysfatal("malloc: %r");
- len = enc64(cbuf, 2*tot, (uchar*)buf, tot);
+ len = enc64(cbuf, len, (uchar*)buf, tot);
print("-----BEGIN %s-----\n", tag);
while(len > 0){
print("%.64s\n", cbuf);