[OLSR-users] Plugin development: how to avoid buffer/packet size overrun when olsr message is of dynamic length.

Andreas Tønnesen (spam-protected)
Wed Jul 14 12:49:38 CEST 2004


My mistake. So much for writing stuff from the top of my head :)

Seems I had forgotten to decrease the max messagesize in the secure
plugin - I'll have it fixed by the nex release.
And yes, the code you suggest is the right way to do this. The 
interface is there(GETD__MAXMESSAGESIZE), so it's just a matter of
fetching a pointer to maxmessagesize and decreasing it.

Sorry about that.


- Andreas 

On Wed, 14 Jul 2004, Christoffer Andersson wrote:

> I have looked through the entire code in the secure plugin and I cannot find any reference to
> GETD_MAXMESSAGESIZE, or any maxmessagesize -= ...
> 
> Is there a remote chance that I have found a bug?  For the moment I cannot figure out
> how you ensure that secure does not exceed the pck size when adding the signature at the end of pck.
> 
> Just to make sure I am looking the right places:
> 
> I have found the definitions of where you get the data and function pointers in olsrd_plugin.h/c.
> 
> Here you have for instance to get the add_ptf function....
> 
> olsr_plugin_io(GETF_ADD_PTF, &add_ptf, sizeof(add_ptf)))
> 
> I cannot find an entry for GETD_MAXMESSAGESIZE.
> 
> And there is no code in any of the files in the secure plugin using a variable starting with max (grep).
> 
> 
> Anyways, since I cannot find the code, I will try to show what I think needs doing:
> 
> 
> I need to add the following in olsrd_plugin.h
> 
> int *maxmessagesize;
> 
> 
> 
> I need to add the following in olsrd_plugin.c (the fetch_olsrd_data() method)
> 
> if( !olsr_plugin_io(GETD_MASMESSAGESIZE,
> 			  &maxmessagesize,
>                     sizeof(maxmessagesize))
> {
>   maxmessagesize = NULL;
>   retval = 0;
> }
> 
> 
> then in my olsrd_myplugin.c I must use the maxmessagesize -= mymessagesize;
> where should this line be to make sure olsr initialises properly?
> Should it go in the olsr_plugin_init() method together with the 
> add_ptf(&add_signature); and similar statements?
> 
> Thanks for all help and don't let my questions ruin your vacation :D
> 
> Christoffer
> 
> 
> -----Original Message-----
> From: Andreas Tønnesen [mailto:(spam-protected)]
> Sent: 13. juli 2004 18:39
> To: Christoffer Andersson
> Cc: (spam-protected)
> Subject: Re: [OLSR-users] Plugin development: how to avoid buffer/packet
> size overrun when olsr message is of dynamic length.
> 
> 
> Hei Christoffer,
> 
> My comments are inline.
> 
> > I am making a plugin where I am adding a packet transform function (add_ptf) to check a packet and add an extra olsr messge at the end.
> > 
> > This ekstra olsr message checks the messages in the packet to build its own message.
> > 
> > This olsr message is therefore dynamic in size.  So far I have come up with the following solution:
> > 
> > Assume that I have to add data from every olsr message in the packet.
> > Find out how much space my new olsr message needs if the packet contains the maximum possible number of the smallest messages in olsr (which is HELLO?).
> > Limit the packet size so that I can always add my message in this scenario, hence never exceeding the packet size.
> > 
> > 1. Is this a valid approach?
> > 
> 
> Yes. But the smallest message is the empty TC. Lets see if I can
> remember this by heart:
> message header 12 bytes + TC header 4 bytes.
> 
> > 2. I am struggling a bit in the code of the secure plugin to find out how you limited the packet size 
> > to make sure that you always have room for the signature at the end of the packet.  I can tell that you 
> > have defined a MAXMESSAGESIZE of 512, but I cannot see where or how you use this to tell olsr that it
> > has to leave room for the signature to avoid packet buffer overrun, or max packet size overrun.
> 
> The maximum bytes olsrd will put in a OLSR packet is set by the global
> variable maxmessagesize(not to be confused with the MAXMESSAGESIZE
> symbol) defined in defs.h. The plugin can access this
> variable trough the GETD__MAXMESSAGESIZE command. In the security
> plugin you'll probably see something like:
> maxmessagesize -= sizeof(signature_message);
> 
> This makes sure there is enough room left in the outputbuffer for the
> signature message.
> 
> Hope this was of help!
> 
> - Andreas 
> 
> -- 
> Andreas Tønnesen((spam-protected))
> UniK University Graduation Center
> University of Oslo
> http://www.olsr.org
> 

-- 
Andreas Tønnesen((spam-protected))
UniK University Graduation Center
University of Oslo
http://www.olsr.org



More information about the Olsr-users mailing list