valgrind indicated that RC4() writes beyond the end of the output buffer which
was was of the same size than the input buffer. Workaround this by rounding up
the output buffer size to a multiple of 8.
cf = crypt_data_array[fd].send;
if (cf) {
void *private = crypt_data_array[fd].private_data;
- unsigned char *outbuf = para_malloc(len);
+ /* RC4 may write more than len to the output buffer */
+ unsigned char *outbuf = para_malloc(ROUND_UP(len, 8));
(*cf)(len, (unsigned char *)buf, outbuf, private);
ret = sendall(fd, (char *)outbuf, &len);
free(outbuf);
p = para_realloc(p, size); \
} \
}
+
+/* Round up x to a multiple of y */
+#define ROUND_UP(x, y) (((x) + (y - 1) / (y)) * (y))