Commit Graph
845 Commits
Author SHA1 Message Date
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
Olaf Bergmann 92ecd52454 coap_io.c: platform-specific network I/O for FreeBSD
Processing of ancillary data for IPv4 works different on FreeBSD. This
change uses IP_RECVDSTADDR instead of IP_PKTINFO on FreeBSD.

Setting a the source address with IP_SENDSRCADDR always failed with
error 22 (Invalid argument) for sendmsg() and thus has not been
implemented. Note that for IPv4, this is not a big problem as there
is usually only one interface address even if bound to INADDR_ANY.
2016-11-19 17:13:01 +01:00
Olaf Bergmann 11e905ed52 address.h: added missing includes
libcoap.h must be included to ensure that platform-specific headers
for the target system are available.
2016-11-19 17:06:36 +01:00
Carsten Schoenert 0ec6fa693a Makefile.am: move target clean-local to distclean-local
Deleting the pkg-config file and also the *.map and *.sym file in a
clean-local target isn't correct as we have no default automatic way to
regenerate *.map and *.sym files before the build of the libcoap is
starting.

Currently there is no need for such a automatic rebuild, the user
normaly doesn't need to do anything on those files. They even don't
should be rebuild by the users in normal cases.
Adding or removing symbols is a sensible thing and the maintenance is
probably up to the developers. Beside that there is the target
'update-map-file' that is used by the developers to (re)build this two
files if needed.

This commit is also adding a new helper target 'dist-local' with a
depency on 'update-map-file' so we are sure to have actual *.map and
*.sym file if we create a tarball for a release.

Moving the .PHONY targets to the end of the Makefile.am as this is the
typical place.
2016-11-18 09:47:46 +01:00
Olaf Bergmann ad40407f88 net.c: improved support for RFC 7967 (No-Response option)
The No-Response option can be used in a request to express disinterest
or interest in certain response classes. This modification adds
No-Response handling for unicast messages and provides basic
functionality for handling multicast responses
2016-11-16 22:24:26 +01:00
Olaf Bergmann 2c7efb77b9 pdu.h: fixed option number for No-Reponse (RFC 7967)
When the No-Response became RFC 7967, the numeric value was changed
to better reflect its characteristics. This modification fixes the
reference in the documentation the option value.
2016-11-16 21:27:01 +01:00
Olaf Bergmann 4585701640 pdu.h: updated RFC numbers in option number comments
The documentation for Observe and Block1/Block2 referenced
outdated Internet Drafts which have become RFCs some time ago.
This change now mentions the correct RFC numbers.
2016-11-16 21:24:22 +01:00
Olaf Bergmann 5a2d68f145 scripts/build.sh: re-enable pkg-config fix for CUnit
The Trusty build environment comes with a pkg-config file for CUnit
which lacks a version number and has a syntax error. The build script
now calls scripts/fix-cunit.sh to create a fixed version of the
existing cunit.pc file and point the configure script to this file.
2016-10-31 13:39:33 +01:00
Olaf Bergmann 87bc3f841a .travis.yml: switch to Trusty build environment, add dependencies
The default build environment lacks pkg-config support for CUnit
causing the new configure script to fail when checking dependencies.

This change also adds docbook-xsl for building the man pages.
2016-10-31 13:36:26 +01:00
Olaf Bergmann 4920a46021 scripts/build.sh: removed non-working cunit.pc fix
Now, PKG_CONFIG_PATH is not set to local version, hoping that the
installed version works without version check.

Added more debug output instead.
2016-10-26 18:56:27 +02:00
Olaf Bergmann c4b5d93ac2 configure.ac: remove cunit version check 2016-10-26 18:56:04 +02:00
Olaf Bergmann 79212255a1 scripts/build.sh: more debug output
This change outputs the config.log when configure failed.
Moreover, a local cunit.pc will be output to see why the build still
fails.
2016-10-26 18:47:08 +02:00
Olaf Bergmann 58ff2feabb scripts/fix-unit.sh: make script executable
Forgot chmod +x scripts/fix-unit.sh.
2016-10-26 18:40:04 +02:00
Olaf Bergmann ab198868f1 scripts/build.sh: added fix for broken cunit.pc in travis CI environment
The pkgconfig specification for libcunit1-dev version 2.1-2 is
horribly broken. build.sh (invoked by the travis CI system,
see .travis.yml) now runs a new script fix-cunit.sh when TESTS is
set to 'yes'.
2016-10-26 18:32:44 +02:00
Olaf Bergmann 5b88c1a2c9 Makefile.am: fix include-path for auto-generated coap.h
coap.h is generated in the build path which is different from the
source tree when building out-of-tree.
2016-10-26 15:39:52 +02:00
Olaf Bergmann 635fe8d33a .travis.yml: added missing packages for documentation
The configure script now uses pkg-config for dependencies checks.
2016-10-26 13:30:13 +02:00
Carsten Schoenert 18f2309759 make: enable out of tree build
The build environment was lacking the possibility to get libcoap
buildable out of tree, simply checkable by the running 'make distcheck'.
Without this fix the users are impossible to build libcoap in a own
folder that's independed from the source containing folder. Typical use
case would be:

  $ mkdir libcoap-build && cd libcoap-build
  $ /path/to/libcoap-source/configure \
      --srcdir=/path/to/libcoap-source \
      --prefix=/somethere/to-install

This commit enables the out of tree build by adding and changing some
needed variables.
2016-10-26 10:46:50 +02:00
Carsten Schoenert 65090de7c8 configure.ac: adapt the output of doxygen compare check
Adapting the text output on the doxygen version compare to the dot check
so the user is seeing more informative things on configure run.
2016-10-26 10:46:50 +02:00
Carsten Schoenert af48b3b31a configure.ac: let configure found the sed binary 2016-10-26 10:46:50 +02:00
Carsten Schoenert 524381eafe configure.ac: normalize helping output for AC_ARG_ENABLE
To get more in sync with the existing output from the default helping
text by various autotools/automake stuff improving a little bit the
existing helper text of some configure arguments.
2016-10-26 10:46:50 +02:00
Carsten Schoenert 7df48fc897 tests/Makefile.am: adding CUNIT_CFLAGS to AM_CFLAGS
The CUNIT_LIBS are already used, the CUNIT_CFLAGS are also needed to
ensure that get also header files that are not inside the default search
patch of the compiler. For example header within /usr/local/include
instead /usr/include.

CUNIT_LIBS and CUNIT_CFLAGS are generated by PKG_CHECK_MODULES([CUNIT] ...
in configure.ac.
2016-10-26 10:46:50 +02:00
Carsten Schoenert 2be9ec9dff configure.ac: simplify the CUnit check by pkg-config
The old behaviour on testing for CUnit library and header files (that
are needed while building the internal testbinary) was done on manually
search for the header and the library file without a real need because
CUnit ships a pkg-config file with a version for longer time.

By using the PKG_CHECK_MODULES macro the check is much easier as the
pkg-config file is serving all the needed information like the search
path for the header files as also LDFLAGS for linking against. This
ensures the environment variables are always setup correctly.

Note that FreeBSD uses for example /usr/include and /user/local/include
for the header files, the pkg-config files can be found in
/usr{/local}/libdata/pkgconfig. The pkg-config file will pick up the
right places then.
2016-10-26 10:46:50 +02:00
Carsten Schoenert de80514661 configure.ac: improve the ERROR message if a2x is missed
Giving the user a better hint if the a2x check isn't succesfull.
2016-10-26 10:46:50 +02:00
Carsten Schoenert 87e30a4e25 configure.ac: adjust a specific FreeBSD test for dot
As FreeBSD uses default the csh (C-shell) or the tcsh (Tennex-shell)
with some different output redirection than bash for example, and the
user might have installed a other shell we need to grep the version from
the dot binary by a csh shell call because this shell be always available.

Happily the 'dot -V' command is quite the same on FreeBSD and Linux
systems. Maybe we need to change this in the future again.
2016-10-26 10:46:50 +02:00
Carsten Schoenert c95e1f0917 configure.ac: adding FreeBSD to the detectable platforms 2016-10-26 10:46:50 +02:00
Carsten Schoenert aa7256a812 configure.ac: splitting ctags check into freebsd specific detection
On FreeBSD the default ctags binary isn't usable for getting the tags
from the header files, we need to take the binary exctags explicitly.
Also before the check can be done we need to know on which platform we
running.
2016-10-26 10:46:50 +02:00
Carsten Schoenert 717b19cede configure.ac: changing tabs into spaces
No technical changes.
We have mixed indention styles, there are spaces and tabs used,
switching all tab indentions into spaces.
This increasing readability of configure.ac on systems with especially
tabwidth>4.
2016-10-26 10:46:50 +02:00
Olaf Bergmann c2dd6b4917 encode.h: fix one-letter pre-processor symbol to avoid conflicts
It was suggested to pick a more specific name for the
pre-processor symbol E in encode.h to prevent name clashes,
see https://github.com/obgm/libcoap/issues/46.
2016-09-22 15:22:28 +02:00
Olaf Bergmann c16918dfff block.c: fixed possible buffer overflow in coap_write_block_opt()
Joel Sandin has pointed out that a buffer flow was possible in
coap_write_block_opt() as the block number is encoded without
range check into the local variable buf. As the block number is
stored in 20 bits, the buffer is enlarged to 4 bytes to fix this.

As a second counter-measure against wrong block numbers, the function
coap_get_block() is modified to check the decoded Block option.
Numbers larger than 0xFFFFF (20 bits) cause this option to be ignored.
2016-09-22 14:39:12 +02:00
Olaf Bergmann d737344b52 client.c: use function parameter in cmdline_subscribe()
cmdline_subscribe() has used the global variable optarg instead of
the local argument that was passed to this function. Changing this
as intended also makes __attribute__((unused)) unneeded.
2016-09-22 12:43:27 +02:00