--- a/sys/crypto/rc4/rc4.c
+++ b/sys/crypto/rc4/rc4.c
@@ -61,6 +61,9 @@
u_char j;
int i, k;
+ if (keylen <= 0)
+ return; /* a non-positive keylen would read key[0] */
+
/* Initialize state with identity permutation */
for (i = 0; i < 256; i++)
state->perm[i] = (u_char)i;