Mercurial > pidgin
comparison libpurple/protocols/qq/qq_crypt.c @ 28213:33921125348d
The output buffer passed to qq_encrypt needs to be 17 bytes bigger
than the data you're encrypting, not 16 bytes bigger. Fixes #10191.
It's hard to say whether this actually causes problems. My guess is
that it does not.
However, the way the qq protocol plugin constructs the plain text
buffer to be passed to qq_encrypt is error prone, and the many calls
to g_newa(guint8, MAX_PACKET_SIZE) are really bad because
MAX_PACKET_SIZE is 64KB. This is a ridiculous amount of space to
request on the stack. All these qq_put8 qq_put16 qq_put32 qq_putdata
functions should be changed to insert data into a dynamically
allocated GString instead of the stack-allocated buffers that they
use now. This eliminates the potential for accidentally overwriting
the end of the buffer.
And the second g_newa() for the output buffer passed into qq_encrypt()
should be changed to allocate space on the heap in most places because,
as previously noted, 64KB is a ridiculous amount of memory to request
from the stack.
Heap allocation may be expensive when compared to stack allocation, but
I feel it's usually worth it to eliminate the possibilty of buffer
overflow.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 04 Sep 2009 22:50:26 +0000 |
parents | 7921a53b94b3 |
children | a8cc50c2279f |
comparison
equal
deleted
inserted
replaced
28210:9af95186dde4 | 28213:33921125348d |
---|---|
169 plain32[0] = crypted32[0] ^ c32_prev[0]; plain32[1] = crypted32[1] ^ c32_prev[1]; | 169 plain32[0] = crypted32[0] ^ c32_prev[0]; plain32[1] = crypted32[1] ^ c32_prev[1]; |
170 } | 170 } |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 /* length of crypted buffer must be plain_len + 16*/ | 174 /* length of crypted buffer must be plain_len + 17*/ |
175 /* | |
176 * The above comment used to say "plain_len + 16", but based on the | |
177 * behavior of the function that is wrong. If you give this function | |
178 * a plain string with len%8 = 7 then the returned length is len+17 | |
179 */ | |
175 gint qq_encrypt(guint8* crypted, const guint8* const plain, const gint plain_len, const guint8* const key) | 180 gint qq_encrypt(guint8* crypted, const guint8* const plain, const gint plain_len, const guint8* const key) |
176 { | 181 { |
177 guint8 *crypted_ptr = crypted; /* current position of dest */ | 182 guint8 *crypted_ptr = crypted; /* current position of dest */ |
178 gint pos, padding; | 183 gint pos, padding; |
179 | 184 |