summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2014-01-10 11:12:21 +0100
committerGravatar Nikias Bassen2014-01-10 11:12:21 +0100
commitc3a37c778ca404beb5e6acd78658a2467d18f3d6 (patch)
tree3683e833c7cca0113b83c7d480f198343167dd00
parent3ab20d711f8a64833e6dcad13766fcf2912ff2e2 (diff)
downloadusbmuxd-c3a37c778ca404beb5e6acd78658a2467d18f3d6.tar.gz
usbmuxd-c3a37c778ca404beb5e6acd78658a2467d18f3d6.tar.bz2
client: fix realloc in send_pkt() that made the buffer smaller instead of larger
-rw-r--r--src/client.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/client.c b/src/client.c
index 5a70edb..330a902 100644
--- a/src/client.c
+++ b/src/client.c
@@ -176,10 +176,16 @@ static int send_pkt(struct mux_client *client, uint32_t tag, enum usbmuxd_msgtyp
176 uint32_t available = client->ob_capacity - client->ob_size; 176 uint32_t available = client->ob_capacity - client->ob_size;
177 /* the output buffer _should_ be large enough, but just in case */ 177 /* the output buffer _should_ be large enough, but just in case */
178 if(available < hdr.length) { 178 if(available < hdr.length) {
179 uint32_t needed_buffer = hdr.length; 179 unsigned char* new_buf;
180 usbmuxd_log(LL_DEBUG, "Enlarging client %d output buffer %d -> %d", client->fd, client->ob_capacity, needed_buffer); 180 uint32_t new_size = ((client->ob_capacity + hdr.length + 4096) / 4096) * 4096;
181 client->ob_buf = realloc(client->ob_buf, needed_buffer); 181 usbmuxd_log(LL_DEBUG, "%s: Enlarging client %d output buffer %d -> %d", __func__, client->fd, client->ob_capacity, new_size);
182 client->ob_capacity = needed_buffer; 182 new_buf = realloc(client->ob_buf, new_size);
183 if (!new_buf) {
184 usbmuxd_log(LL_FATAL, "%s: Failed to realloc.\n", __func__);
185 return -1;
186 }
187 client->ob_buf = new_buf;
188 client->ob_capacity = new_size;
183 } 189 }
184 memcpy(client->ob_buf + client->ob_size, &hdr, sizeof(hdr)); 190 memcpy(client->ob_buf + client->ob_size, &hdr, sizeof(hdr));
185 if(payload && payload_length) 191 if(payload && payload_length)