@@ -515,29 +515,36 @@ void relay_client(int sock, const uint8_t *msg, int32_t len, const ip6_hdr *ip_h
515
515
void callback (evutil_socket_t fd, short event, void *arg) {
516
516
struct relay_config *config = (struct relay_config *)arg;
517
517
static uint8_t message_buffer[4096 ];
518
- uint32_t len = recv (config->filter , message_buffer, 4096 , 0 );
518
+ int32_t len = recv (config->filter , message_buffer, 4096 , 0 );
519
519
if (len <= 0 ) {
520
- syslog (LOG_WARNING, " recv: Failed to receive data at filter socket\n " );
520
+ syslog (LOG_WARNING, " recv: Failed to receive data at filter socket: %s\n " , strerror (errno));
521
+ return ;
521
522
}
522
523
523
524
char * ptr = (char *)message_buffer;
524
- const uint8_t *current_position = (uint8_t *)ptr;
525
+ const uint8_t *current_position = (uint8_t *)ptr;
525
526
const uint8_t *tmp = NULL ;
527
+ const uint8_t *prev = NULL ;
526
528
527
529
auto ether_header = parse_ether_frame (current_position, &tmp);
528
530
current_position = tmp;
529
531
530
532
auto ip_header = parse_ip6_hdr (current_position, &tmp);
531
533
current_position = tmp;
532
534
535
+ prev = current_position;
533
536
if (ip_header->ip6_ctlun .ip6_un1 .ip6_un1_nxt != IPPROTO_UDP) {
534
537
const struct ip6_ext *ext_header;
535
538
do {
536
539
ext_header = (const struct ip6_ext *)current_position;
537
540
current_position += ext_header->ip6e_len ;
541
+ if ((current_position == prev) || (current_position >= (uint8_t *)ptr + sizeof (message_buffer))) {
542
+ return ;
543
+ }
544
+ prev = current_position;
538
545
}
539
546
while (ext_header->ip6e_nxt != IPPROTO_UDP);
540
- }
547
+ }
541
548
542
549
auto udp_header = parse_udp (current_position, &tmp);
543
550
current_position = tmp;
0 commit comments