Merge pull request #460 from mrdeep1/without_tcp_split_uri_fix

DISABLE_TCP: Make TCP enabled code checking more rigorous
This commit is contained in:
obgm authored and GitHub committed 2020-02-24 13:49:34 +01:00
commit 66e6fca48e
5 files changed
+40 -7

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
libcoap_src = pdu.c net.c coap_debug.c encode.c uri.c subscribe.c resource.c str.c option.c async.c block.c mem.c coap_io.c coap_session.c coap_notls.c coap_hashkey.c address.c
libcoap_src = pdu.c net.c coap_debug.c encode.c uri.c subscribe.c resource.c str.c option.c async.c block.c mem.c coap_io.c coap_session.c coap_notls.c coap_hashkey.c address.c coap_tcp.c
libcoap_dir := $(filter %libcoap,$(APPDS))
vpath %c $(libcoap_dir)/src
+7
View File
@@ -829,6 +829,13 @@ cmdline_uri(char *arg, int create_uri_opts) {
return -1;
}
if (uri.scheme==COAP_URI_SCHEME_COAP_TCP && !coap_tcp_is_supported()) {
/* coaps+tcp caught above */
coap_log(LOG_EMERG,
"coap+tcp URI scheme not supported in this version of libcoap\n");
return -1;
}
if (uri.port != get_default_port(&uri) && create_uri_opts) {
coap_insert_optlist(&optlist,
coap_new_optlist(COAP_OPTION_URI_PORT,
+1 -1
View File
@@ -39,7 +39,7 @@ CFLAGS += -I$(top_srcdir)/include/coap2
vpath %.c $(top_srcdir)/src
COAPOBJS = net.o coap_debug.o option.o resource.o pdu.o encode.o subscribe.o coap_io_lwip.o block.o uri.o str.o coap_session.o coap_notls.o coap_hashkey.o address.o
COAPOBJS = net.o coap_debug.o option.o resource.o pdu.o encode.o subscribe.o coap_io_lwip.o block.o uri.o str.o coap_session.o coap_notls.o coap_hashkey.o address.o coap_tcp.o
CFLAGS += -g3 -Wall -Wextra -pedantic -O0 -fpack-struct
# not sorted out yet
+31 -3
View File
@@ -658,8 +658,33 @@ coap_session_create_client(
coap_session_t *session = NULL;
assert(server);
assert(proto != COAP_PROTO_NONE);
switch(proto) {
case COAP_PROTO_UDP:
break;
case COAP_PROTO_DTLS:
if (!coap_dtls_is_supported()) {
coap_log(LOG_CRIT, "coap_new_client_session*: DTLS not supported\n");
return NULL;
}
break;
case COAP_PROTO_TCP:
if (!coap_tcp_is_supported()) {
coap_log(LOG_CRIT, "coap_new_client_session*: TCP not supported\n");
return NULL;
}
break;
case COAP_PROTO_TLS:
if (!coap_tls_is_supported()) {
coap_log(LOG_CRIT, "coap_new_client_session*: TLS not supported\n");
return NULL;
}
break;
case COAP_PROTO_NONE:
default:
assert(0);
break;
}
session = coap_make_session(proto, COAP_SESSION_TYPE_CLIENT, local_if,
local_if, server, 0, ctx, NULL);
if (!session)
@@ -1024,12 +1049,15 @@ coap_new_endpoint(coap_context_t *context, const coap_address_t *listen_addr, co
goto error;
}
#if !COAP_DISABLE_TCP
if (proto == COAP_PROTO_TLS && !coap_tls_is_supported()) {
coap_log(LOG_CRIT, "coap_new_endpoint: TLS not supported\n");
goto error;
}
#endif /* !COAP_DISABLE_TCP */
if (proto == COAP_PROTO_TCP && !coap_tcp_is_supported()) {
coap_log(LOG_CRIT, "coap_new_endpoint: TCP not supported\n");
goto error;
}
if (proto == COAP_PROTO_DTLS || proto == COAP_PROTO_TLS) {
if (!coap_dtls_context_check_keys_enabled(context)) {
-2
View File
@@ -79,7 +79,6 @@ coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri) {
}
/* There might be and addition "+tcp", indicating reliable transport: */
#if !COAP_DISABLE_TCP
if (len>=4 && p[0] == '+' && p[1] == 't' && p[2] == 'c' && p[3] == 'p' ) {
p += 4;
len -= 4;
@@ -88,7 +87,6 @@ coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri) {
else
uri->scheme = COAP_URI_SCHEME_COAP_TCP;
}
#endif /* !COAP_DISABLE_TCP */
q = (const uint8_t *)"://";
while (len && *q && *p == *q) {
++p; ++q; --len;