From 9f31ab32123f830fe5d32ff969a5d5e92e17edeb Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Fri, 21 Dec 2012 16:21:05 +0100 Subject: [PATCH] bugfix in option length encoding (pointed out by Timm Decker) --- configure.in | 2 +- option.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/configure.in b/configure.in index 8649244e..533d7121 100644 --- a/configure.in +++ b/configure.in @@ -7,7 +7,7 @@ # README for terms of use. AC_PREREQ([2.65]) -AC_INIT([libcoap], [3.0.0]) +AC_INIT([libcoap], [3.0.1]) AC_CONFIG_SRCDIR([coap.h]) # First check for Contiki build to quit configure before any other test diff --git a/option.c b/option.c index 926a1683..5b270ba5 100644 --- a/option.c +++ b/option.c @@ -184,7 +184,7 @@ coap_opt_value(coap_opt_t *opt) { while (*++p == 0xff && n++ < 3) ; - return p; + return ++p; /* point to next byte after length indicator */ } size_t @@ -221,9 +221,10 @@ coap_opt_setlength(coap_opt_t *opt, size_t maxlen, size_t length) { if (maxlen <= res) return 0; - opt++; - memset(opt, 0xff, res); - *opt = length & 0xff; + memset(opt, 0xff, res-1); + opt[res] = length & 0xff; + + ++res; } return res;