pemencode: handle base64 input length < 3, fix bogus zero termination

This commit is contained in:
cinap_lenrek 2015-03-12 17:44:33 +01:00
parent 757354dac6
commit e437b1b289

View file

@ -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);