Menu ▾ ▴

#17 coap_opt_size underestimates space usage

v1.0_(example)
closed-fixed
None
5
2013-09-03
2013-04-22
chrysn
No

when responding to a message containing a block2 option when it is not whitelisted, a "WARN coap_add_data: cannot add: data too large for PDU" comes out of the coap_new_error_response function. i've traced it down in the debugger to COAP_OPT_SIZE adding 2 bytes to the total length, while 3 bytes get finally added to the message.

a gdb session log (attached) shows where things go wrong: between $14 and $15 (in the per-option size-adding loop), size grows by 2, but between $20 and $21, length grows by 3.

i'll try to set up a minimal example to find the bug more easily.

1 Attachments

Discussion

  • chrysn

    chrysn - 2013-04-23

    @minimal example: the coap-server example shows the problem when requesting /time with block2 set. (tested with copper client configured to coap-13, block2=0).

     
  • Olaf Bergmann

    Olaf Bergmann - 2013-04-30
    • assigned_to: Olaf Bergmann
     
  • Olaf Bergmann

    Olaf Bergmann - 2013-04-30

    Thanks for tracking this down. I will have a look at this.

     
  • tbahls

    tbahls - 2013-08-15

    I think this is an example of a more general problem in coap_new_error_response(), when it is compiled to add text to the response payload. The problem is that the payload calculation only reflects the size of the error response string, and does not account for the one byte payload marker that will also be required. In my testing I found that all error responses provoked this same "data too large for PDU", and the debugger showed that all were just one byte short.

    My fix was to change the initial payload size calculation to this:

    if (phrase)
        size += 1 + strlen(phrase);
    

    - Tom

     
  • Olaf Bergmann

    Olaf Bergmann - 2013-09-03
    • status: open --> closed-fixed
     
  • Olaf Bergmann

    Olaf Bergmann - 2013-09-03

    Thanks again for the reminder. This one was a bit tricky. The fix is in commit 095e2ee629b5176eff7044ed431587e6c0b1cbbf.