Skip to content

Commit 153c9c4

Browse files
caeiesDimitriPapadopoulos
authored andcommitted
Io: don't write garbage at the end of the stream.
* Thanks valgrind for pinning this out.
1 parent e1b1da7 commit 153c9c4

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/io.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,14 +1241,14 @@ static void *pppd_write(void *arg)
12411241
if (tunnel->config->tun) {
12421242
void *pkt_type = pkt_data(packet);
12431243

1244-
len = packet->len;
1244+
len = packet->len - 2;
12451245
switch (ntohs(*(uint16_t *)pkt_type)) {
12461246
case PPP_LCP:
1247-
lcp_packet(tunnel, pkt_data(packet) + 2, len - 2);
1247+
lcp_packet(tunnel, pkt_data(packet) + 2, len);
12481248
free(packet);
12491249
continue;
12501250
case PPP_IPCP:
1251-
ipcp_packet(tunnel, pkt_data(packet) + 2, len - 2);
1251+
ipcp_packet(tunnel, pkt_data(packet) + 2, len);
12521252
free(packet);
12531253
continue;
12541254
case PPP_IP:
@@ -1258,13 +1258,13 @@ static void *pppd_write(void *arg)
12581258
goto out_free_packet;
12591259
}
12601260

1261-
hdlc_buffer = malloc(packet->len);
1261+
hdlc_buffer = malloc(len);
12621262
if (hdlc_buffer == NULL) {
12631263
log_error("malloc: %s\n", strerror(errno));
12641264
break;
12651265
}
12661266

1267-
memcpy(hdlc_buffer, pkt_data(packet) + 2, packet->len - 2);
1267+
memcpy(hdlc_buffer, pkt_data(packet) + 2, len);
12681268
} else {
12691269
size_t hdlc_bufsize = estimated_encoded_size(packet->len);
12701270

0 commit comments

Comments
 (0)