From e437b1b289354c9d390b400f1c9c215857848126 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Thu, 12 Mar 2015 17:44:33 +0100 Subject: pemencode: handle base64 input length < 3, fix bogus zero termination --- sys/src/cmd/auth/pemencode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/src/cmd/auth/pemencode.c b/sys/src/cmd/auth/pemencode.c index b6e886fa5..24df22cf4 100644 --- a/sys/src/cmd/auth/pemencode.c +++ b/sys/src/cmd/auth/pemencode.c @@ -48,11 +48,11 @@ main(int argc, char **argv) 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); -- cgit v1.2.3