]> git.tuebingen.mpg.de Git - paraslash.git/commit
RC4: Fix invalid read.
authorAndre Noll <maan@systemlinux.org>
Thu, 3 Mar 2011 14:09:53 +0000 (15:09 +0100)
committerAndre Noll <maan@systemlinux.org>
Thu, 3 Mar 2011 15:19:00 +0000 (16:19 +0100)
commit1199398188c1a5ee0e8bc147400d8532bc874700
tree2eff2a96d539a2c68dbd3c51138fd45e2a3571f3
parentf7527caf231e06672f6079026eeb338a68e69474
RC4: Fix invalid read.

Commit 7cb8fa26 (May 2010) created a target buffer for the RC4-encoded
data which is slightly larger than the input buffer because openssl
apparently wrote beyond the size it was told to write.

As it turns out, this was not enough as RC4() may also read-overflow
the input buffer. Valgrind says on Linux/x86_64:

==2423== Invalid read of size 8
==2423==    at 0x5312020: RC4 (in /lib/libcrypto.so.0.9.8)
==2423==    by 0x40F01D: rc4_send_bin_buffer (crypt.c:224)
==2423==    by 0x40C724: com_stat (command.c:391)
==2423==    by 0x40BABF: handle_connect (command.c:838)
==2423==    by 0x408330: command_post_select (server.c:404)
==2423==    by 0x41B5DA: schedule (sched.c:76)
==2423==    by 0x4089C3: main (server.c:581)
==2423==  Address 0x6cefeb8 is 232 bytes inside a block of size 235 alloc'd
==2423==    at 0x4C275A2: realloc (vg_replace_malloc.c:525)
==2423==    by 0x40DE74: para_realloc (string.c:40)
==2423==    by 0x40E324: make_message (string.c:134)
==2423==    by 0x40C5D0: com_stat (command.c:328)
==2423==    by 0x40BABF: handle_connect (command.c:838)
==2423==    by 0x408330: command_post_select (server.c:404)
==2423==    by 0x41B5DA: schedule (sched.c:76)
==2423==    by 0x4089C3: main (server.c:581)

Fix this by treating the last len % 8 bytes of the input
separately. It's ugly but it does silence valgrind and should not be
noticeably slower since we are only doing one extra copy of at most
7 bytes.

We need to round the input size up and down to a multiple of 8,
so this patch introduces generic macros in para.h for this purpose.
crypt.c
para.h