Skip to content

Commit e9a8005

Browse files
author
Diebbo
committed
FIX: CVE vulnerabilities
1 parent 6662e48 commit e9a8005

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

modules/pico_dns_common.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*********************************************************************
2-
* PicoTCP-NG
2+
* PicoTCP-NG
33
* Copyright (c) 2020 Daniele Lacamera <[email protected]>
44
*
55
* This file also includes code from:
66
* PicoTCP
77
* Copyright (c) 2012-2017 Altran Intelligent Systems
88
* Authors: Toon Stegen, Jelle De Vleeschouwer
9-
*
9+
*
1010
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
1111
*
1212
* PicoTCP-NG is free software; you can redistribute it and/or modify
@@ -120,9 +120,17 @@ pico_dns_decompress_name( char *name, pico_dns_packet *packet )
120120
uint16_t decompressed_index = 0;
121121
char *label = NULL, *next = NULL;
122122

123+
if (!name || !packet) {
124+
pico_err = PICO_ERR_EINVAL;
125+
return NULL;
126+
}
127+
123128
/* Reading labels until reaching to pointer or NULL terminator.
124129
* Only one pointer is allowed in DNS compression, the pointer is always the last according to the RFC */
125130
dns_name_foreach_label_safe(label, name, next, PICO_DNS_NAMEBUF_SIZE) {
131+
if (!lable || (*lable & 0xFF) >= PICO_DNS_NAMEBUF_SIZE) {
132+
return NULL;
133+
}
126134

127135
uint8_t label_size = (uint8_t)(*label+1);
128136
if (decompressed_index + label_size >= PICO_DNS_NAMEBUF_SIZE) {
@@ -140,6 +148,12 @@ pico_dns_decompress_name( char *name, pico_dns_packet *packet )
140148
/* Found compression bits */
141149
ptr = (uint16_t)((((uint16_t) *label) & 0x003F) << 8);
142150
ptr = (uint16_t)(ptr | (uint16_t) *(label + 1));
151+
152+
/* Check if the pointer is within the packet */
153+
if (ptr >= packet->len) {
154+
return NULL;
155+
}
156+
143157
label = (char *)((uint8_t *)packet + ptr);
144158

145159
dns_name_foreach_label_safe(label, label, next, PICO_DNS_NAMEBUF_SIZE-decompressed_index) {

modules/pico_mdns.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*********************************************************************
2-
* PicoTCP-NG
2+
* PicoTCP-NG
33
* Copyright (c) 2020 Daniele Lacamera <[email protected]>
44
*
55
* This file also includes code from:
66
* PicoTCP
77
* Copyright (c) 2012-2017 Altran Intelligent Systems
88
* Authors: Toon Stegen, Jelle De Vleeschouwer
9-
*
9+
*
1010
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
1111
*
1212
* PicoTCP-NG is free software; you can redistribute it and/or modify
@@ -26,6 +26,7 @@
2626
*
2727
*********************************************************************/
2828
#include "pico_config.h"
29+
#include "pico_dns_common.h"
2930
#include "pico_stack.h"
3031
#include "pico_addressing.h"
3132
#include "pico_socket.h"
@@ -934,7 +935,7 @@ pico_mdns_record_delete( void **record )
934935
* Creates a single standalone mDNS resource record with given name, type and
935936
* data.
936937
*
937-
* @param S TCP/IP stack reference
938+
* @param S TCP/IP stack reference
938939
* @param url DNS rrecord name in URL format. Will be converted to DNS
939940
* name notation format.
940941
* @param _rdata Memory buffer with data to insert in the resource record. If
@@ -1040,7 +1041,7 @@ pico_mdns_cookie_delete( void **ptr )
10401041
/* ****************************************************************************
10411042
* Creates a single standalone mDNS cookie
10421043
*
1043-
* @param S TCP/IP stack reference
1044+
* @param S TCP/IP stack reference
10441045
* @param qtree DNS questions you want to insert in the cookie.
10451046
* @param antree mDNS answers/authority records you want to add to cookie.
10461047
* @param artree mDNS additional records you want to add to cookie.
@@ -1050,7 +1051,7 @@ pico_mdns_cookie_delete( void **ptr )
10501051
* @return Pointer to newly create cookie, NULL on failure.
10511052
* ****************************************************************************/
10521053
static struct pico_mdns_cookie *
1053-
pico_mdns_cookie_create( struct pico_stack *S,
1054+
pico_mdns_cookie_create( struct pico_stack *S,
10541055
pico_dns_qtree qtree,
10551056
pico_mdns_rtree antree,
10561057
pico_mdns_rtree artree,
@@ -1466,7 +1467,7 @@ pico_mdns_my_records_probed( pico_mdns_rtree *records )
14661467
PICO_FREE(record->stack->mdns_hostname);
14671468
}
14681469
/* Re-allocate hostname from given rname */
1469-
record->stack->mdns_hostname =
1470+
record->stack->mdns_hostname =
14701471
pico_dns_qname_to_url(found->record->rname);
14711472
}
14721473

@@ -2190,6 +2191,12 @@ pico_mdns_handle_data_as_answers_generic(struct pico_stack *S,
21902191
return -1;
21912192
}
21922193

2194+
// check that the number of answare/response corrispond to the number of questions
2195+
if (count != pico_tree_count(&S->MDNSOwnRecords)) {
2196+
mdns_dbg("Number of answers does not match the number of questions\n");
2197+
return -1;
2198+
}
2199+
21932200
/* TODO: When receiving multiple authoritative answers, */
21942201
/* they should be sorted in lexicographical order */
21952202
/* (just like in pico_mdns_record_am_i_lexi_later) */
@@ -3000,7 +3007,7 @@ pico_mdns_getrecord_generic(struct pico_stack *S, const char *url, uint16_t typ
30003007
}
30013008

30023009
/* Associate the current TCP/IP stack reference to access relevant
3003-
* fields/trees
3010+
* fields/trees
30043011
*/
30053012
q->stack = S;
30063013

0 commit comments

Comments
 (0)