Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIXING main vul #26

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions modules/pico_dns_client.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*********************************************************************
* PicoTCP-NG
* PicoTCP-NG
* Copyright (c) 2020 Daniele Lacamera <[email protected]>
*
* This file also includes code from:
* PicoTCP
* Copyright (c) 2012-2017 Altran Intelligent Systems
* Authors: Kristof Roelants
*
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
*
* PicoTCP-NG is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -596,9 +596,6 @@ static void pico_dns_client_callback(uint16_t ev, struct pico_socket *s)
}

header = (struct pico_dns_header *)dns_response;
domain = (char *)header + sizeof(struct pico_dns_header);
qsuffix = (struct pico_dns_question_suffix *)pico_dns_client_seek(domain);
/* valid asuffix is determined dynamically later on */

if (pico_dns_client_check_header(header) < 0)
return;
Expand All @@ -607,6 +604,11 @@ static void pico_dns_client_callback(uint16_t ev, struct pico_socket *s)
if (!q)
return;

// FIX: what if the query is not a PTR query?
domain = (char *)header + sizeof(struct pico_dns_header);
qsuffix = (struct pico_dns_question_suffix *)pico_dns_client_seek(domain);
/* valid asuffix is determined dynamically later on */

if (pico_dns_client_check_qsuffix(qsuffix, q) < 0)
return;

Expand Down Expand Up @@ -873,4 +875,3 @@ int pico_dns_client_init(struct pico_stack *S)


#endif /* PICO_SUPPORT_DNS_CLIENT */

18 changes: 16 additions & 2 deletions modules/pico_dns_common.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*********************************************************************
* PicoTCP-NG
* PicoTCP-NG
* Copyright (c) 2020 Daniele Lacamera <[email protected]>
*
* This file also includes code from:
* PicoTCP
* Copyright (c) 2012-2017 Altran Intelligent Systems
* Authors: Toon Stegen, Jelle De Vleeschouwer
*
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
*
* PicoTCP-NG is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -120,9 +120,17 @@ pico_dns_decompress_name( char *name, pico_dns_packet *packet )
uint16_t decompressed_index = 0;
char *label = NULL, *next = NULL;

if (!name || !packet) {
pico_err = PICO_ERR_EINVAL;
return NULL;
}

/* Reading labels until reaching to pointer or NULL terminator.
* Only one pointer is allowed in DNS compression, the pointer is always the last according to the RFC */
dns_name_foreach_label_safe(label, name, next, PICO_DNS_NAMEBUF_SIZE) {
if (!lable || (*lable & 0xFF) >= PICO_DNS_NAMEBUF_SIZE) {
return NULL;
}

uint8_t label_size = (uint8_t)(*label+1);
if (decompressed_index + label_size >= PICO_DNS_NAMEBUF_SIZE) {
Expand All @@ -140,6 +148,12 @@ pico_dns_decompress_name( char *name, pico_dns_packet *packet )
/* Found compression bits */
ptr = (uint16_t)((((uint16_t) *label) & 0x003F) << 8);
ptr = (uint16_t)(ptr | (uint16_t) *(label + 1));

/* Check if the pointer is within the packet */
if (ptr >= packet->len) {
return NULL;
}

label = (char *)((uint8_t *)packet + ptr);

dns_name_foreach_label_safe(label, label, next, PICO_DNS_NAMEBUF_SIZE-decompressed_index) {
Expand Down
21 changes: 19 additions & 2 deletions modules/pico_dns_sd.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*********************************************************************
* PicoTCP-NG
* PicoTCP-NG
* Copyright (c) 2020 Daniele Lacamera <[email protected]>
*
* This file also includes code from:
* PicoTCP
* Copyright (c) 2012-2017 Altran Intelligent Systems
* Authors: Jelle De Vleeschouwer
*
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
*
* PicoTCP-NG is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -73,9 +73,26 @@ pico_dns_sd_kv_vector_strlen( kv_vector *vector )
/* Iterate over the key-value pairs */
for (i = 0; i < vector->count; i++) {
iterator = pico_dns_sd_kv_vector_get(vector, i);

if (!iterator || iterator->key){
pico_err = PICO_ERR_EINVAL;
return 0;
}

if (len + 1u + strlen(iterator->key) > PICO_DNS_SD_KV_MAXLEN) {
pico_err = PICO_ERR_EINVAL;
return 0;
}

len = (uint16_t) (len + 1u + /* Length byte */
strlen(iterator->key) /* Length of the key */);

if (iterator->value) {
if (len + 1u + strlen(iterator->value) > PICO_DNS_SD_KV_MAXLEN) {
pico_err = PICO_ERR_EINVAL;
return 0;
}

len = (uint16_t) (len + 1u /* '=' char */ +
strlen(iterator->value) /* Length of value */);
}
Expand Down
10 changes: 7 additions & 3 deletions modules/pico_dns_sd.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*********************************************************************
* PicoTCP-NG
* PicoTCP-NG
* Copyright (c) 2020 Daniele Lacamera <[email protected]>
*
* This file also includes code from:
* PicoTCP
* Copyright (c) 2012-2017 Altran Intelligent Systems
*
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
*
* PicoTCP-NG is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -44,6 +44,11 @@ typedef struct
#define PICO_DNS_SD_KV_VECTOR_DECLARE(name) \
kv_vector (name) = {0}

/* ****************************************************************************
* Maximum length of a key-value pair.
* ****************************************************************************/
#define PICO_DNS_SD_KV_MAXLEN (0xFFFFu)

/* ****************************************************************************
* Just calls pico_mdns_init in it's turn to initialise the mDNS-module.
* See pico_mdns.h for description.
Expand Down Expand Up @@ -108,4 +113,3 @@ pico_dns_sd_kv_vector_add( kv_vector *vector, char *key, char *value );


#endif /* _INCLUDE_PICO_DNS_SD */

21 changes: 14 additions & 7 deletions modules/pico_mdns.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*********************************************************************
* PicoTCP-NG
* PicoTCP-NG
* Copyright (c) 2020 Daniele Lacamera <[email protected]>
*
* This file also includes code from:
* PicoTCP
* Copyright (c) 2012-2017 Altran Intelligent Systems
* Authors: Toon Stegen, Jelle De Vleeschouwer
*
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
*
* PicoTCP-NG is free software; you can redistribute it and/or modify
Expand All @@ -26,6 +26,7 @@
*
*********************************************************************/
#include "pico_config.h"
#include "pico_dns_common.h"
#include "pico_stack.h"
#include "pico_addressing.h"
#include "pico_socket.h"
Expand Down Expand Up @@ -934,7 +935,7 @@ pico_mdns_record_delete( void **record )
* Creates a single standalone mDNS resource record with given name, type and
* data.
*
* @param S TCP/IP stack reference
* @param S TCP/IP stack reference
* @param url DNS rrecord name in URL format. Will be converted to DNS
* name notation format.
* @param _rdata Memory buffer with data to insert in the resource record. If
Expand Down Expand Up @@ -1040,7 +1041,7 @@ pico_mdns_cookie_delete( void **ptr )
/* ****************************************************************************
* Creates a single standalone mDNS cookie
*
* @param S TCP/IP stack reference
* @param S TCP/IP stack reference
* @param qtree DNS questions you want to insert in the cookie.
* @param antree mDNS answers/authority records you want to add to cookie.
* @param artree mDNS additional records you want to add to cookie.
Expand All @@ -1050,7 +1051,7 @@ pico_mdns_cookie_delete( void **ptr )
* @return Pointer to newly create cookie, NULL on failure.
* ****************************************************************************/
static struct pico_mdns_cookie *
pico_mdns_cookie_create( struct pico_stack *S,
pico_mdns_cookie_create( struct pico_stack *S,
pico_dns_qtree qtree,
pico_mdns_rtree antree,
pico_mdns_rtree artree,
Expand Down Expand Up @@ -1466,7 +1467,7 @@ pico_mdns_my_records_probed( pico_mdns_rtree *records )
PICO_FREE(record->stack->mdns_hostname);
}
/* Re-allocate hostname from given rname */
record->stack->mdns_hostname =
record->stack->mdns_hostname =
pico_dns_qname_to_url(found->record->rname);
}

Expand Down Expand Up @@ -2190,6 +2191,12 @@ pico_mdns_handle_data_as_answers_generic(struct pico_stack *S,
return -1;
}

// check that the number of answare/response corrispond to the number of questions
if (count != pico_tree_count(&S->MDNSOwnRecords)) {
mdns_dbg("Number of answers does not match the number of questions\n");
return -1;
}

/* TODO: When receiving multiple authoritative answers, */
/* they should be sorted in lexicographical order */
/* (just like in pico_mdns_record_am_i_lexi_later) */
Expand Down Expand Up @@ -3000,7 +3007,7 @@ pico_mdns_getrecord_generic(struct pico_stack *S, const char *url, uint16_t typ
}

/* Associate the current TCP/IP stack reference to access relevant
* fields/trees
* fields/trees
*/
q->stack = S;

Expand Down
4 changes: 2 additions & 2 deletions modules/pico_mdns.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* ****************************************************************************
* PicoTCP-NG
* PicoTCP-NG
* Copyright (c) 2020 Daniele Lacamera <[email protected]>
*
* This file also includes code from:
* PicoTCP
* Copyright (c) 2012-2017 Altran Intelligent Systems
*
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
*
* PicoTCP-NG is free software; you can redistribute it and/or modify
Expand Down
Loading