Commit Graph
1343 Commits
Author SHA1 Message Date
Jon Shallow bf5dd5a82f coap-{client|server}: Add in PKI Support. Tidy up Usage output
examples/client.c

Add in support for using PKI certificates

examples/coap-server.c

Add in support for using PKI certificates
remove default PSK key
Add in '-h hint' option

Make Usage reflect actual options available to use

man/coap-client.txt.in

Include the missing options
Update -A option to be a single entity
Sort the options into ascending order as reported by Usage

man/coap-server.txt.in

Include the missing options
Add in '-h hint' option
2018-07-03 15:06:17 +01:00
Olaf Bergmann 118bbebbbc pdu.h: add COAP_OPTION_SIZE2
This change closes issue #210 [1].

[1] https://github.com/obgm/libcoap/issues/210
2018-06-26 10:04:33 +02:00
Olaf Bergmann 98ae07b1c2 Dockerfile.build-env: install git to enable travis builds
The LwIP build requires git to work, so this must be available
in the build-env docker image.
2018-06-25 11:54:20 +02:00
Olaf Bergmann 767a24ebfc added Dockerfiles for building the travis environment 2018-06-25 11:35:02 +02:00
obgm df4bad7e08 Merge pull request #200 from mrdeep1/issue-199
Fix end byte overrun in coap_opt_parse() if 2 byte sequence
2018-06-13 16:41:35 +02:00
Jon Shallow c5cd313ea3 option.c: Fix end byte overrun in coap_opt_parse() if 2 byte sequence
tests/test_pdu.c: Create t_parse_pdu15() which shows the issue

Credit to OSS-Fuzz for finding this - work done by Bhargava Shastry with
the libcoap testing
2018-06-13 11:46:51 +01:00
Olaf Bergmann 0f8a3b334f coap-rd.c: remove type cast from RD_ROOT_STR
To ensure correct use of RD_ROOT_STR in coap_make_str_const() the
type cast to const uint8_t * has been removed.
This change addresses CID 1469634.
2018-06-06 16:49:12 +02:00
Olaf Bergmann df7b36edd5 client.c: explicitly restrict URI port number to 16 bits
To document that uri.port input to coap_encode_var_safe() never
has more than 16 bits, an explicit bit mask has been added. This
change is supposed to avoid the false positive CID 1469635.
2018-06-06 16:42:47 +02:00
Olaf Bergmann ec9bf6eb4a client.c: fix bug in Accept option parser
cmdline_content_type() treated option numbers as 8-bit integers and
therefore could not parse values >255. Now, option numbers are
represented as uint16_t to allow for numbers between 0 and 65535.

Moreover, as RFC 7252 has made the Accept option non-repeatable,
cmdline_content_type() now will only add a single Accept option.
2018-06-06 16:30:40 +02:00
Olaf Bergmann 97d32e68c8 README.md: included cross-reference to libcoap-minimal
libcoap-minimal [1] contains small client and server examples that
illustrate the use of libcoap-2.

This change also updates the copyright year.

[1] https://github.com/obgm/libcoap-minimal
2018-06-05 15:26:03 +02:00
Olaf Bergmann 171f25e123 client.c: fix -Wstringop-overflow warning in cmdline_token()
Calling strncpy() on the variable (and erroneous) calculated token
length in cmdline_token() has caused stringop-overflow warning by
GCC 8. This change fixes the error and replaces strncpy() by
memcpy() to quieten the compiler.
2018-06-05 12:28:40 +02:00
obgm a5f98ef639 Merge pull request #175 from mrdeep1/coap_encode_var_bytes
Make coap_encode_var_bytes() safe by not allowing buffer overruns
2018-06-05 11:23:37 +02:00
Jon Shallow c7e9359f02 Make coap_encode_var_bytes() by replacing with coap_encode_var_safe()
Update code / examples / man pages with the updated function.

include/coap/libcoap.h:
Add in new define COAP_DEPRECATED to generate compiler warnings when used

include/coap/encode.h
New coap_encode_var_safe() function that includes the size of the output
buffer as a parameter.

Make coap_encode_var_bytes() a wrapper for coap_encode_var_safe() and
mark it as COAP_DEPRECATED for backwards compatability

src/encode.c:
New coap_encode_var_safe() function that includes the size of the output
buffer as a parameter.

examples/coap-server.c:
examples/contiki/server.c:
Make the ticks resource consistent in case
2018-06-05 09:41:58 +01:00
obgm 60f699d535 Merge pull request #189 from mrdeep1/optlist-mem-leak
options: Fix subtle memory leak in coap_add_optlist_pdu()
2018-06-04 14:05:01 +02:00
obgm f107701f71 Merge pull request #194 from mrdeep1/response-leak
Cleaner fix for CID 1382587 that catches another case
2018-06-04 12:50:17 +02:00
Jon Shallow f9a16c2d7a src/net.c: Cleaner fix for CID 1382587 that catches another case 2018-06-04 11:29:36 +01:00
obgm 6ced5e2e49 Merge pull request #193 from mrdeep1/gcc-diagnostic
coap_{notls|openssl|tinydtls}.c: Support older gcc compilers
2018-06-04 12:17:06 +02:00
Jon Shallow 7abe7714c3 coap_{notls|openssl|tinydtls}.c: Support older gcc compilers
#pragma GCC diagnostic push
 #pragma GCC diagnostic pop

is not supported by gcc version less than 4.6

[I also think the push/pop is not needed as it is at the end of the
file and only one file is complied at one time]

gcc in general does not complain about (when the only entry in the file)

static inline void dummy(void) {
}

Also current code before fix is unlikely to work on Windows so the
additional compiler wrapper (is it clang) tests should fix this.
2018-06-04 10:06:37 +01:00
obgm eba6ce8e12 Merge pull request #195 from rdewaele/forward-declaration-typo
fix typographical error in forward declaration
2018-06-04 10:33:24 +02:00
Robrecht Dewaele 9677376902 fix typographical error in forward declaration 2018-06-02 03:42:45 +02:00
Olaf Bergmann 26d5cf784a coap_{notls,openssl,tinydtls}.c: quiet 'unused function' warning
Depending on the TLS library being used (which may be none), the
code that depends on other TLS libraries is not compiled. Because
some compilers are not happy compiling empty modules, each of these
files contains an empty static inline function dummy() that gets
compiled instead. As clang happens to emit a warning for this
function when -Wunused-function is set, this change introduces
a GCC pragma (sic!) to suppress this warning for the dummy function.
2018-05-31 11:12:01 +02:00
Olaf Bergmann 8e446e732a client.c: Remove unused function set_timeout()
The function is not used because most of the timer handling has
been moved to coap_run_once().

This change avoids clang to emit a warning due to -Wunused-function.
2018-05-31 11:12:01 +02:00
obgm 282fd96fc3 Merge pull request #192 from cquijano/dtls_event_on_error
coap_tinydtls.c: On DTLS error, fire and event that could be catch by upper layers
2018-05-31 10:43:12 +02:00
Carlos Quijano 491964e9c4 coap_tinydtls.c: On DTLS error, fire and event that can be caught by upper layers 2018-05-31 10:33:56 +02:00
obgm 4cfc722bf1 Merge pull request #181 from mrdeep1/coap-server-crash
coap-server: Sanity check of input to hnd_put_time() to prevent crashes
2018-05-31 10:24:32 +02:00
Jon Shallow 9fa448e439 options: Fix subtle memory leak in coap_add_optlist_pdu()
coap_add_optlist_pdu() sorted the options for insertion, but did not update
the coap_optlist_t head (whch may then no longer point to the first entry in the
sorted chain) and so when coap_delete_optlist() was called, the first few
entries of the sorted chain may not get deleted.
Fixed by making it
 coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t** optlist_chain)
instead of
 coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t* optlist_chain)

Additionally deleted options_start() and options_next() as they are not
required - Issue #184.

examples/client.c:
Fix coap_add_optlist_pdu() call

include/coap/options.h:
Fix coap_add_optlist_pdu() call

libcoap-2.{map|sym}:
Delete options_start()

man/coap_observe.txt.in:
man/coap_pdu_setup.txt.in:

Update docmentation

src/option.c:
Update coap_add_optlist_pdu()

tests/test_pdu.c:
New tests for checkout out coap_insert_optlist() and coap_add_optlist_pdu()
functions
2018-05-30 11:38:50 +01:00
Olaf Bergmann 232f2612f2 updated submodule ext/tinydtls 2018-05-28 13:26:10 +02:00
Olaf Bergmann 56caa06677 test_session.c: fix warning for taken absolute value of unsigned int
This change replaces the call of abs(v - ref) to avoid a compiler
warning for -Wabsolute-value:

test_session.c:95:11: warning: taking the absolute value of unsigned type 'unsigned int' has no effect
      [-Wabsolute-value]
  return (abs(v - ref) / 100.0) <= FP_ERR_THRESHOLD;
2018-05-28 13:26:10 +02:00
obgm 90cd1ac193 Merge pull request #173 from mrdeep1/const_value
Remove cast-qual compiler warnings
2018-05-28 13:23:19 +02:00
Jon Shallow 34dbf512b0 libcoap-2.{sym|map}: Add in coap_new_str_const() and coap_delete_str_const() 2018-05-25 16:38:08 +01:00
Jon Shallow f7bbd4a85a man/c*.in, man/Mkefile.am: Update text and examples for -Wcast-qual warnings
General:
Embolden -lcoap linking definitions
Embolden NOTE:

man/Makefile:
Reduce data written into missing .3 files

man/coap_attribute.txt.in:
Fix a typo
2018-05-25 16:38:08 +01:00
Jon Shallow 25a8414105 src/*.c: Remove cast-qual compiler warnings
Where appropriate in general

Replace 'unsigned char' with 'const uint8_t'
Replace 'str' with 'coap_str_c_t'
Replace str with coap_string_t
Prefix with 'const' some type casts
Remove unnecessary type casting
Remove unneeded WITH_LWIP wrappers to select coap_malloc_type() or memp_malloc()
as underlying  coap_malloc_type() is correctly selected in include/coap/mem.h

src/block.c:
Replace coap_opt_const_value() with coap_opt_value()

src/coap_io.c:
Due to the definations of struct iovec and struct msghdr, and const parameters
getting passed in, as this is a write of data function, the pointers are
copied into the 2 structures to get around the cast-qual warnings

src/net.c:
Release any sessions (so that they may get freed off) in coap_free_context()

src/option.c:
coap_option_filter_get() had to be downgraded as coap_option_filter_op() is
used by set functions as well.

src/pdu.c:
Remove const out of next_option_safe() parameters

As coap_resource_init() has a const uri_path parameter passed into it, it is not
possible to have these values legally freed off if flags is set to
COAP_RESOURCE_FLAGS_RELEASE_URI.

coap_resource_init_release() has been created to handle this.  However, as it
is likely to be called with a coap_string_t generated from a call to
coap_get_uri_path(), the string must be correctly freed off.  Hence the
use of coap_string_t as a parameter.

coap_add_attr_release() has been added in as well, using coap_string_t* as
parameters, to allow the coap_string_t to be freed off correctly.

Add in coap_log warning if the functions coap_resource_init*() and
coap_add_attr*() are called incorrectly.

Update src
2018-05-25 16:38:07 +01:00
Jon Shallow b4fc68c554 include/coap/*.h: Remove cast-qual compiler warnings
Commented out coap_opt_block_set_m() as it is not used anywhere, and needs
to get rewritten if needed.

Removed / changed references to coap_opt_const_value()

Created a new struct coap_str_const_t to handle const parameters
Add in 2 new functions to create / delete the new string type
coap_new_str_const()
coap_delete_str_const()
Added in coap_make_str_const() to help create the necessary string equivalents
of the ascii test string.  Note that the byte array must be in the
local scope.

Make coap_string_equal() a macro to handle differing string types

Made uri_path a pointer in coap_resource_t
Made name and value a pointer in coap_attribute_t

Reasoning behind this was triggerred by test t_wellknown3() creating a
number of resources, all using the same string buffer, so they all ended up
with the same uri-path (last update to uri-path).  In the days of hashing
uri-path for the lookup would have worked, but the wrong uri-path
presented from the resource.  Now we always allocate uri-path if
application does not want it freed off - and always free it off at time
or resource removal.  The same is also true for coap_add_attr().

Updated coap_resource_init(), coap_add_attr() and coap_find_attr() to
pass in string parameters, rather than use a pointer to data and a length.

Where appropriate

Replace 'unsigned char' with 'const uint8_t'
Replace 'str' with 'coap_str_const_t'
Replace 'str' with 'coap_string_t'
Prefix with 'const' some type casts
Remove 'const' prefix from some type casts
2018-05-25 16:37:05 +01:00
Jon Shallow af84f2049b configure.ac: Add -Wcast-qual to WARNING_OPTIONS 2018-05-25 14:11:04 +01:00
Jon Shallow 7dc16ed184 tests/*.c, examples/*.c: Remove cast-qual compiler warnings
Created new 'CU_ASSERT_PTR_EQUAL_C(actual, expected)' to handle const variable matching

Where appropriate

Replace 'unsigned char' with 'const uint8_t'
Replace 'str' with 'coap_str_c_t'
Replace 'str' with 'coap_string_t'
Prefix with 'const' some type casts
Update coap_add_attr() calls inline with updated API
Update coap_resource_init() calls inline with updated API
Make use of coap_make_str_const() for defining parameters

tests*/.c
Update code to stop memory leaks (as found by valgrind)

examples/coap-rd.c
Track the fact that uri_path in coap_resource_t is now a pointer
2018-05-25 14:11:04 +01:00
obgm 2023f0107a Merge pull request #188 from mrdeep1/flexible-menber
option.[ch]: Fix "warning: ISO C++ forbids flexible array member 'data'
2018-05-22 17:49:59 +02:00
Jon Shallow a17757ec6e async.[ch]: Fix flexible array member 'token' warning
Make token[] token[8] as the maximum size of a token is 8 bytes

Check that we do not overflow coap_async_state_t when copying in
the token.
2018-05-22 11:32:58 +01:00
Jon Shallow 856236dc6c option.[ch]: Fix "warning: ISO C++ forbids flexible array member 'data' " 2018-05-22 10:42:13 +01:00
Olaf Bergmann a2d263356e configure.ac: enable -Wwrite-strings
As discussed in bug #185 [1], const strings should be protected
from being overwritten. This change adds -Wwrite-strings to the
compiler warning flags and fixes resulting warnings by making
static strings const.

[1] https://github.com/obgm/libcoap/issues/185
2018-05-19 09:27:50 +02:00
Jon Shallow 828967bb43 examples/coap-server.c: Sanity check of input to hnd_put_time to prevent core
The input value for time in hnd_put_time() is not sanity checked for the
upper limit.  If too large, gmtime() etc. functions will return a failure
(errno is EOVERFLOW).

Validate the input value to hnd_put_time().  Return 4.00 if failure

Verify return from gmtime() in hnd_get_time() before trying to convert to
ascii readable string. Return 4.04 if failure.
[Time may just be valid when updated in hnd_put_time(), but then
increments to be too large - hence check also in hnd_get_time()]
2018-05-18 15:10:09 +01:00
obgm 9f68329f70 Merge pull request #178 from mrdeep1/tid-duplication
Verify tid is not being re-used in a session
2018-05-18 15:58:11 +02:00
obgm 2782082808 Merge pull request #186 from mrdeep1/response-resource-leak
Fix CID 1382587 response resource leak
2018-05-18 15:41:17 +02:00
Jon Shallow 884e7d9162 src/net.c: Fix CID 1382587 response resource leak 2018-05-18 14:07:11 +01:00
Olaf Bergmann c2301257d0 option.h: Fixed bug in doxygen comment.
s/@pdu/@p pdu/
2018-05-18 14:41:47 +02:00
Olaf Bergmann 64610da8a0 Makefile.am: fix errors for target dist
* Added missing headers for unit tests to EXTRA_DIST.
* Moved utlist.h to EXTRA_DIST.
* Use correct name for .pc pkg-config template.
2018-05-18 14:39:15 +02:00
Olaf Bergmann 99fbe78a47 resource.h: get rid of -Winline warning
As gcc 7 complains that coap_register_handler() is too large to
be inlined automatically, the function definition now has been
moved to resource.c.

This change also updates the symbol mappings accordingly.
2018-05-18 13:40:05 +02:00
obgm 06d3a44e98 Merge pull request #177 from mrdeep1/traffic-restart
coap main loop may wait un-necessarily in select() call when in fact there is work to do
2018-05-18 13:31:12 +02:00
obgm 95d82ad41e Merge pull request #162 from mrdeep1/issue-154
Move handling of CoAP Options into libcoap, instead of it all being held in coap-client
2018-05-18 13:15:42 +02:00
Jon Shallow 02195e13a6 examples/coap_list.[ch]: Document that these files are DEPRECATED
/*
 * examples/coap_list.[ch] are DEPRECATED.  You should be using
 * struct coap_optlist_t instead with the following functions which are a part
 * of libcoap.
 *
 * coap_new_optlist()
 * coap_insert_optlist()
 * coap_delete_optlist()
 * coap_add_optlist_pdu()
 *
 * See 'man coap_pdu_setup' for further information.
 *
 * examples/coap_list.[ch] files will be removed in a future release
 * They are left here to support building backward compatability of old versions
 * of coap-client
 */
2018-05-17 19:02:21 +01:00
Jon Shallow 2b81487c03 src/pdu.c: Warn and prevent token being added twice
Update with new library naming
2018-05-17 19:02:21 +01:00