]> err.no Git - yubikey-server-c/commitdiff
Don't rely on strings being null-terminated.
authorTollef Fog Heen <tfheen@err.no>
Mon, 19 Oct 2009 13:20:16 +0000 (15:20 +0200)
committerTollef Fog Heen <tfheen@err.no>
Mon, 19 Oct 2009 13:20:16 +0000 (15:20 +0200)
src/util.c

index 7e856cf544f1946f5095229e70c7b33842b254dc..4ae25237bfcd3b05c5f9ce8440af0c1a88b348f6 100644 (file)
@@ -114,7 +114,9 @@ static void ysc_b64_encodeblock(unsigned char in[3], unsigned char out[4], int l
        out[0] = cb64[in[0] >> 2];
        out[1] = cb64[((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4)];
        out[2] = (unsigned char) (len > 1 ? cb64[((in[1] & 0x0f) << 2) |
-                                                ((in[2] & 0xc0) >> 6)] : '=');
+                                                (len > 2 ? 
+                                                 ((in[2] & 0xc0) >> 6) :
+                                                 0 )] : '=');
        out[3] = (unsigned char) (len > 2 ? cb64[in[2] & 0x3f] : '=');
 }