Commit Graph
874 Commits
Author SHA1 Message Date
jcmichelou e2c2dc5326 Make LIBCOAP_PACKAGE_XXX macros usables in code 2017-05-06 18:24:59 +02:00
jcmichelou 3042a287bc Fix a problem with the use of control structures in sendmsg / recvmsg. These are not struct sockaddr, they are ip_pktinfo or ipv6_pktinfo, so local_interface->addr.size is irrelevant, even causing an overflow with writing zero bytes outside of the control structure on the stack, even though it happens to work because the buffer is large enough.
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.
2017-05-06 16:56:32 +02:00
jcmichelou 9e8a693ffd Fix typo on ipv6 notation for the multicast group address for coap. 2017-05-05 20:48:18 +02:00
jcmichelou 9b3cf894fc Use crypto secure version of rand to generate the message ids on windows. 2017-05-05 20:46:29 +02:00
jcmichelou 3ee4552dcf Merge fix to coap_config.h.contiki from PR #47. 2017-05-05 20:33:48 +02:00
jcmichelou f25f962427 Add win32 binaries for the CUnit library (as a DLL because of LGPL) so the regression tests can be run on windows. 2017-05-05 20:31:57 +02:00
jcmichelou 9b647d5d05 Add visual studio 2015 solution and project files for building libcoap on windows.
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.
2017-05-05 20:29:10 +02:00
Olaf Bergmann 771f013b6e coap-server.c: fixed resource check time calculation
This change is a fix for issue #72 [1].

[1] https://github.com/obgm/libcoap/issues/72
2017-04-12 22:40:34 +02:00
Olaf Bergmann ac94964b45 pdu.h: new methods FETCH, PATCH, iPATCH from RFC 8132 2017-04-07 10:14:22 +02:00
obgm f446afdf1e Merge pull request #74 from PawelWMS/transaction_id_fix
Reverting coap_transaction_id() to work the way it did.
2017-04-04 12:10:33 +02:00
Pawel Winogrodzki 6112604569 Makingcoap_transaction_id() always use the peer for ID generation. 2017-04-04 02:32:45 -07:00
obgm bcd4019d3a Merge pull request #70 from PawelWMS/W4_fix_upstream_develop
Fixing /W4 warnings for Windows builds.
2017-03-29 13:18:03 +02:00
Pawel Winogrodzki b130109c04 Applying agreed changes. 2017-03-29 02:51:21 -07:00
Pawel Winogrodzki 4b112431ff Changing u_short to uint16_t inside pdu.c. 2017-03-28 17:15:37 -07:00
Pawel Winogrodzki d6d7df8bfe Fixing comments inside coap_time.c and net.c. 2017-03-28 17:04:46 -07:00
Pawel Winogrodzki 48fb2443df Fixing coap_io.c comments. 2017-03-28 16:54:23 -07:00
Pawel Winogrodzki 8090dc7ba8 Fixing other sources needing <limits.h>. 2017-03-20 17:07:29 -07:00
Pawel Winogrodzki 45805772ca Adding <limits.h> to pdu.c.
It seems that POSIX builds didn't understand what
"USHRT_MAX" means and that macro is defined inside limits.h.
2017-03-20 16:59:06 -07:00
Pawel Winogrodzki a42894b053 Removing unnecessary line in coap_time.c. 2017-03-20 16:54:37 -07:00
Pawel Winogrodzki fc3e33b011 Fixing invalid coap_io.c line. 2017-03-20 16:41:27 -07:00
Pawel Winogrodzki 9adc4eb6a7 Fixing /W4 warnings for Windows builds.
Removing all of the /W4 level warnings from the code.
No functional changes.

Signed-off-by: Pawel Winogrodzki <pawelwi@microsoft.com>
2017-03-20 15:48:33 -07:00
obgm b425b150c2 Merge pull request #67 from PawelWMS/remove_failed_observers_loop_fix
Fixing coap_remove_failed_observers() loop.
2017-03-11 11:28:16 +01:00
Pawel Winogrodzki 445383a0b5 Fixing coap_remove_failed_observers() loop.
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>
2017-03-10 17:55:34 -08:00
Pawel Winogrodzki eb1fae94ed Fixing Option Delta and Option Length encoding.
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>
2017-03-08 11:09:27 +01:00
Olaf Bergmann d7763a295a test_options.c: unit test for extended delta
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).
2017-03-08 11:05:31 +01:00
Olaf Bergmann fa52486030 README.md: added tool badges v4.1.2 2017-01-13 16:02:58 +01:00
Olaf Bergmann c6d142df43 libcoap-1.{map,sym}: updated map files
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.
2017-01-06 09:28:58 +01:00
Olaf Bergmann 6468887a12 .gitignore: do not ignore custom files in m4
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.
2016-12-16 12:29:46 +01:00
Olaf Bergmann 292b0f0790 address.[hc]: Fixed byteorder in coap_is_mcast() on platform posix
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.
2016-12-15 11:12:22 +01:00
Olaf Bergmann fb66920d5f net.c: Fix response code for unknown resources
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.
2016-12-14 19:56:14 +01:00
Anton Glukhov bbe8ffab7f Fix big/little endian alignment
Signed-off-by: Anton Glukhov <anton.a.glukhov@gmail.com>
2016-12-08 15:00:02 +01:00
Olaf Bergmann 6d882f6ed5 client.c: fix TOCTOU for file input
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.
2016-12-02 13:43:45 +01:00
Olaf Bergmann 53183e63b2 coap-server.c: discard result of coap_get_data()
coap_get_data() sets the given result parameter size to 0 if no
data is available. The function's result therefore can be neglected
in hnd_put_time().
2016-12-02 13:35:32 +01:00
Olaf Bergmann d9cb9c826c client.c: abort on invalid URI at command line
cmdline_uri() now aborts operation if an invalid URI was passed
as argument.
2016-12-02 13:22:07 +01:00
Olaf Bergmann df2a6d1f10 test_error_response.c: free storage from responses
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.
2016-12-02 13:18:38 +01:00
Olaf Bergmann 8edf84ef53 Merge PR 56 2016-12-02 10:32:28 +01:00
Olaf Bergmann 037678c4c0 Merge branch 'pr/client-block1-size-robustness' of git://github.com/gebart/libcoap into gebart-pr/client-block1-size-robustness 2016-12-02 10:23:32 +01:00
Joakim Nohlgård f7a17c975e examples/client: Fix Block1 handling for growing block sizes
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.
2016-12-02 09:52:17 +01:00
Olaf Bergmann 6437190232 pdu.c: check for zero length before invoking memcmp()
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).
2016-12-01 17:12:42 +01:00
Olaf Bergmann 731a3f7cbb test_pdu.c: fix condition inside CUnit assertion
The test condition accidentally contained an assignment instead
of the equal operator.
2016-12-01 17:11:11 +01:00
Olaf Bergmann beeb6b62d4 net.c: re-arrange code to avoid memory leakage
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.
2016-12-01 16:50:11 +01:00
Olaf Bergmann 41af3304f0 net.c: explicitly clear pointer to free'd storage
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().
2016-12-01 14:50:16 +01:00
Olaf Bergmann 4721d5d527 coap_io.c: avoid use of tainted data from recvmsg
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.
2016-12-01 14:10:31 +01:00
Joakim Nohlgård ed6ca0efd6 debug: Fix off-by-1 error in coap_show_pdu block size output 2016-12-01 13:02:28 +01:00
Olaf Bergmann 0fd7695733 pdu.c: Added missing response phrases
Some response phrases were missing in the data structure coap_error
that is used to return a humna-readable error description in a
diagnostic payload.
2016-12-01 13:01:07 +01:00
Jean-Philippe Comtois 718b2dfad5 pdu.c: correct response codes for 2.xx
Fixed response codes and reason phrase for diagnostic payloads
for 2.xx responses.
2016-12-01 12:58:16 +01:00
Carsten Schoenert 72eec07777 configure.ac: adding detection of kfreebsd platforms
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.
2016-11-25 09:29:10 +01:00
Olaf Bergmann 85733a6acb client.c: Added missing option -U in usage info
The new option '-U' was missing in the usage information of
coap-client and the corresponding part of the manual page.
2016-11-19 17:39:48 +01:00
Ken Bannister 572e7110e0 Allow client example to not generate Uri-Host and Uri-Port options.
* Via new command line option, -U.
2016-11-19 17:34:44 +01:00
Olaf Bergmann 8054981362 coap_io.c: removed erraneous memcpy() in coap_network_read()
@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.
2016-11-19 17:22:12 +01:00