[riot-notifications] [RIOT-OS/RIOT] net/nanocoap: verify simple reply buffer (#10855)

Ken Bannister notifications at github.com
Wed Jan 23 23:55:19 CET 2019


### Contribution description
coap_reply_simple() is a single function to write a reply, including a payload. However, it writes the payload before verifying the available buffer length. This PR refactors this function to verify first. This PR also updates the documentation for coap_build_reply(), on which coap_reply_simple() depends, to describe how to ensure the length comparison is accurate.

### Testing procedure
Test with /riot/board resource in the nanocoap_server example. 

- in coap_handler.c, modify _riot_board_handler() to use "arduino-duemilanove" as the name of the board, rather than the definition of RIOT_BOARD, which is "native"
- in main.c, modify COAP_INBUF_SIZE to 27
- in sock.c, enable debug
- also build gcoap
- create a tap bridge with `tapsetup -c 2`, start nanocoap_server for tap0 and gcoap for tap1

>From the gcoap terminal,
```
> coap get <tap0-addr> 5683 /riot/board
coap get <tap0-addr> 5683 /riot/board
gcoap_cli: sending msg ID 46325, 17 bytes
> gcoap: response Success, code 2.05, 19 bytes
arduino-duemilanove
```

Now recompile main.c with COAP_INBUF_SIZE set to 26, and run the test again. In this case, the request times out. On the server terminal, you will see `error handling request -28`

### Issues/PRs references
-none-
You can view, comment on, or merge this pull request online at:

  https://github.com/RIOT-OS/RIOT/pull/10855

-- Commit Summary --

  * net/nanocoap: make reply doc more specific
  * net/nanocoap: fix remaining space calculation
  * net/nanocoap: verify reply length before write

-- File Changes --

    M sys/include/net/nanocoap.h (11)
    M sys/net/application_layer/nanocoap/nanocoap.c (11)

-- Patch Links --

https://github.com/RIOT-OS/RIOT/pull/10855.patch
https://github.com/RIOT-OS/RIOT/pull/10855.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/10855
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190123/996f9f4a/attachment.html>


More information about the notifications mailing list