Comments (5)
@MrHulu Thanks for raising this. What is considered is a critical bug is when libcoap internally calls a function which causes the application to crash. The challenge we have here is when an application passes in information that is malformed that causes libcoap to crash. In particular, when buffers are passed in that are not properly formed in terms of size and location, they are virtually impossible to detect without running some sort of memory usage checker.
In the case of the pdu
being NULL as you highlighted above, it is easy to add in pdu == NULL
checks and either return a dummy value (which does not necessarily indicate an error) or have assert(pdu != NULL)
which will give an assertion error (no real difference to a crash) as the application code really needs to be handling the pdu == NULL
scenario.
coap_response_handler_t
is only called when libcoap is confident that the received pdu
is a genuine match for a previously sent pdu
. Thus the token
for the received pdu
will be one that matches a previously sent pdu
. According to RFC7252, matching mid
at the application layer is not safe to do and tokens
should be matched. So, if you want to do this matching, then you need to maintain a list of sent
pdu tokens to match against, rather than relying on sent
pdu being set.
from libcoap.
Hi, @mrdeep1
I understand that the function is badly handled and can only be used by the caller to determine if the data is NULL.
But my suggestion is to mark it in the comments?
from libcoap.
Now I have a new challenge, when I use the libcoap-minimal project, I find that the server can't respond to the client's request. Can you tell me why?
Environment
- libcoap version: v4.3.1-154-gcca6b5f
- Build System: [Make|CMake]
- Operating System: [Window]
Code to reproduce this issue
diff --git a/client.cc b/client.cc
index a37d80f..91d9004 100644
--- a/client.cc
+++ b/client.cc
@@ -22,10 +22,10 @@ main(void) {
coap_startup();
/* Set logging level */
- coap_set_log_level(LOG_WARNING);
+ coap_set_log_level(LOG_DEBUG);
/* resolve destination address where server should be sent */
- if (resolve_address("coap.me", "5683", &dst) < 0) {
+ if (resolve_address("192.168.5.149", "5688", &dst) < 0) {
coap_log(LOG_CRIT, "failed to resolve address\n");
goto finish;
}
diff --git a/server.cc b/server.cc
index 1d02cbe..bf8f235 100644
--- a/server.cc
+++ b/server.cc
@@ -20,7 +20,7 @@ main(void) {
coap_startup();
/* resolve destination address where server should be sent */
- if (resolve_address("localhost", "5683", &dst) < 0) {
+ if (resolve_address("192.168.5.149", "5688", &dst) < 0) {
coap_log(LOG_CRIT, "failed to resolve address\n");
goto finish;
}
Debug Logs
In client.exe
Jun 06 10:59:38.274 DEBG ***192.168.5.149:63076 <-> 192.168.5.149:5688 UDP : session 00EEB2C8: created outgoing session
Jun 06 10:59:38.276 DEBG ***192.168.5.149:63076 <-> 192.168.5.149:5688 UDP : session connected
v:1 t:CON c:GET i:5bfa {} [ Uri-Path:hello ]
Jun 06 10:59:38.277 DEBG * 192.168.5.149:63076 <-> 192.168.5.149:5688 UDP : netif: sent 16 bytes
v:1 t:CON c:GET i:5bfa {} [ Uri-Path:hello, Request-Tag:0xe28057 ]
Jun 06 10:59:38.277 DEBG ** 192.168.5.149:63076 <-> 192.168.5.149:5688 UDP : mid=0x5bfa: added to retransmit queue (2344ms)
In server.exe
v:1 t:CON c:GET i:5bfa {} [ Uri-Path:hello, Request-Tag:0xe28057 ]
v:1 t:ACK c:2.05 i:5bfa {} [ ] :: 'world'
Jun 06 10:59:38.279 CRIT coap_socket_send: An invalid argument was supplied.
from libcoap.
Please raise this as a separate issue, as well as provide the libcoap-minimal git version and enable debug logging on the server.
from libcoap.
#1128 The server has debug logging enabled
from libcoap.
Related Issues (20)
- Request token is unexpectedly replaced with nonsense HOT 15
- Q-Block support detection fails in some cases HOT 5
- [Non-conformance] Handling CoAP Invalid Versions HOT 2
- No callback if DTLS connection with OpenSSL server and client fails due to PSK mismatch HOT 3
- Add coap_get_resource_from_uri_path() to man pages. HOT 2
- HTTP/S Support for Proxy URIs in CoAP to HTTP Proxy HOT 4
- [Non-conformance] Handling Unreapeatable Options HOT 1
- Incorrect header passed to response_handler after finishing Replay Window scenario. HOT 7
- Actively denying a new session HOT 4
- Failing to set mtu when WOLFSSL_DTLS_MTU is enabled HOT 1
- Assertion !lock->in_callback failed in coap_lock_lock_func() during application shutdown HOT 10
- Build with wolfSSL not loading certificates on server side HOT 3
- Memory leak in LwIP function `coap_udp_recvs` HOT 1
- PDU use after free when sending an OSCORE message with OSCORE disabled at build time HOT 5
- coap-client binary PSK HOT 17
- [Question] Proxy-scheme and proxy-uri example with coap-client and coap-server applications HOT 6
- Make coap_print_wellknown customizable HOT 6
- Wrong
- Access Token option addition to libcoap HOT 1
- Clarification on cancelling a block-wise request in the middle of transaction at client's end HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libcoap.