Prevent invalid addresses from being used as source address with sendmsg. On linux, they are just ignored, so it is the same as not specifying one, but on windows they cause an error. In both case it is simpler not to include any control info if the intent is to let the interface be chosen by the network stack.
Merge changes from PR #47 related to windows platform support.
Add full windows platform support including correct error checking and working regression tests and examples.
Remove need to build applications using libcoap with -DWITH_POSIX and to include coap_config.h. This applies to the examples as well.
The loop was always exiting after analysing the first observer,
so in case there were more and the first one on the list of
observers didn't match the one we wanted to remove, the
observer never got removed.
Signed-off-by: Pawel Winogrodzki <pawelwi@microsoft.com>
Option Delta and Option Length were being encoded incorrectly
the value 269 and ended up being encoded the same way as 13.
For details please see RFC-7252 "Option Format"
( https://tools.ietf.org/html/rfc7252#page-17 ).
Signed-off-by: Pawel Winogrodzki <pawelwi@microsoft.com>
PR #65 reports wrong encoding of option value 269. The new
unit test t_encode_option9() tests for correct encoding
according to [RFC 7252, Section 3.1](https://tools.ietf.org/html/rfc7252#section-3.1).
For platform posix, the function coap_is_mcast() was moved to address.c
as it has become too large to be inlined by the compiler. This
modification updates the map files accordingly.
Ignoring the subtree m4/ cannot be overridden by subsequent rules.
To include the ax_*.m4 macro sets, the auto-generated files to be
ignored in the m4 directory must be listed explicitly.
This change addresses bug #58.
As IN_MULTICAST does a 32 bit comparison in host byte order,
sin_addr.s_addr needs to be converted using ntohl(). This change
also moves the coap_is_mcast() implementation to address.c because
it has become too complex for inlining.
John Carter has pointed out that non-GET requests for a resource
that does not exist caused a 4.05 response ("Method not allowed").
This fix corrects this behavior to return 4.04 in case a resource
does not exist and, for .well-known/core, 4.05 if anything but
a GET request was received.
The function cmdline_input_from_file() allocates a chunk of memory
to hold the contents of the given file. As libcoap does not offer
an interface to realloc(), we have to determine the required buffer
size before starting to read from the file, leading to a classical
TOCTOU condition.
This change mitigates the defect by first opening the file and then
calling fstat(). Note that the subsequent fread() call takes the
size of the pre-allocated buffer into account.
Free the storage allocated by coap_new_error_response() in unit tests.
This change simplifies automated leak checks as it avoids cluttering
the output with almost false positives.
Only increment block size if it can be done without causing gaps or
overlaps in the byte sequence.
The patch adds a check for alignment to ensure that no gaps appear when
a server responds with a larger block size than the original request
was using.
Ignore the block number sent by the server since that may or may not be
valid. Always recompute based on how many bytes have been sent so far.
Rationale:
Erbium (Contiki CoAP) responds to Block1 request with a Block1 option
containing the server's maximum supported Block1 size (Contiki
configuration option REST_MAX_CHUNK_SIZE). However, the block number
in the Block1 option is the same number as the block number of the
original request.
In coap_pdu_parse(), everything but the header is copied by memcmp()
from the packet to the PDU structure. An additional check ensures
that memcmp() is invoked only when there is data to copy (i.e. the
incoming CoAP message consists of more than just the base header).
On platforms other than Contiki coap_new_context() has returned NULL
when no listen address was supplied but did not free the memory that
was previously allocated for the context object.
This change re-arranges the checks to return before allocating memory.
Static code analysis tools have incorrectly reported a memory leak
in function handle_request(). To avoid this false positive, the
variable response is explicitly set to NULL after releasing the
memory with coap_delete_pdu().
coap_network_read() has used the address size reported by recvmsg()
in the msg_namelen field. As this value might be taken from the
incoming packet, coverity scan reports this value as a possible
security issue.
This fix sets the address size to the expected size and drops the
received packet if msg_namelen differs.
kFreeBSD is a modificated FreeBSD system by Debian with a FreeBSD kernel
and GNU C library (libc) used for the applications. After adding FreeBSD
support for libcoap no more changes needed to get libcoap compiled with
a kFreeBSD installation.
@john-carter has pointed out in bug #48 that valgrind reports
overlapping source and dest ranges in memcpy(). As the source
and destination in this memcpy() invocation are exactly the
same, it can be deleted safely.
For testing, the memcpy() has been replaced by an assert that
checks if these fields are alsways the same.