mirror of
https://github.com/irssi/irssi.git
synced 2026-08-08 19:30:15 +02:00
dcc: enforce declared receive size
DCC GET trusts the sender-provided size for UI and auto-get policy but continues writing until the peer closes the connection. A sender can advertise a small file and exhaust the receiver filesystem. Limit each read to the remaining declared byte count and close the transfer once that count has been reached.
This commit is contained in:
parent
68131a09be
commit
880da53aad
1 changed files with 11 additions and 2 deletions
|
|
@ -150,15 +150,24 @@ static void sig_dccget_send(GET_DCC_REC *dcc)
|
|||
/* input function: DCC GET received data */
|
||||
static void sig_dccget_receive(GET_DCC_REC *dcc)
|
||||
{
|
||||
int ret;
|
||||
uoff_t remaining;
|
||||
int ret, read_size;
|
||||
|
||||
if (dcc_get_recv_buffer == NULL) {
|
||||
dcc_get_recv_buffer = g_malloc(DCC_GET_RECV_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (dcc->transfd >= dcc->size) {
|
||||
dcc_close(DCC(dcc));
|
||||
return;
|
||||
}
|
||||
|
||||
remaining = dcc->size - dcc->transfd;
|
||||
read_size = remaining > DCC_GET_RECV_BUFFER_SIZE ?
|
||||
DCC_GET_RECV_BUFFER_SIZE : (int) remaining;
|
||||
ret = net_receive(dcc->handle, dcc_get_recv_buffer,
|
||||
DCC_GET_RECV_BUFFER_SIZE);
|
||||
read_size);
|
||||
if (ret == 0) break;
|
||||
|
||||
if (ret < 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue