If the buffer is too short, it is still totally legal to call all of the
later cbor statements, so I'm not sure how that happened.  All that
should happen after the first time is that would be the increment of the
'size needed'.

The tinycbor library is really good about not writing past the buffer,
unless you lie to it about how much was allocated.  I'm sure Thiago
would be really interested to see a situation where this isn't the case.

-Erich

On Fri, 2015-10-23 at 17:55 +0000, Light, John J wrote:
> Playing with the code, I ran across a situation where the cbor reported an 
> error (because the buffer was too short), and I got a SIGSEGV in a later cbor 
> statement because nobody had tested 'err' yet.  Since the buffers are 
> allocated rationally, this is unlikely to happen in practice.  Still...
> 
> John
> 
> -----Original Message-----
> From: iotivity-dev-bounces at lists.iotivity.org [mailto:iotivity-dev-bounces 
> at lists.iotivity.org] On Behalf Of Keane, Erich
> Sent: Friday, October 23, 2015 10:49 AM
> To: Macieira, Thiago
> Cc: iotivity-dev at lists.iotivity.org
> Subject: Re: [dev] question about payload coding
> 
> Yep, thanks Thiago.  That is the situation where we use err = err | vs err = 
> err ||, since that is the only error code we are capable of recovering from.
> 
> 
> On Fri, 2015-10-23 at 10:47 -0700, Thiago Macieira wrote:
> > On Friday 23 October 2015 17:41:12 Keane, Erich wrote:
> > > The err = err | <cbor function> is only used in a few places where 
> > > knowing the error afterwards is important, for most situations, the 
> > > error code is pretty meaningless since there is nothing we can do 
> > > about it.
> > 
> > To be clear: there's only one error code that is important here and 
> > that's the "buffer is too short" when encoding the data. TinyCBOR has 
> > that in a special bit that no other error code will set, so it's guaranteed 
> > to work.
> > 
> > Moreover, you *can* continue streaming data after you got such an 
> > error and TinyCBOR will then simply count how many bytes it needs, instead 
> > of encoding.
> > At the end, you can allocate the buffer of the size that TinyCBOR says 
> > it should be and encoding should work (provided you have the same 
> > data, of course).
> > 
> 
> _______________________________________________
> iotivity-dev mailing list
> iotivity-dev at lists.iotivity.org
> https://lists.iotivity.org/mailman/listinfo/iotivity-dev

Reply via email to