[quagga-dev 3069] Re: bugs related to length of interface names

Paul Jakma paul at clubi.ie
Fri Apr 1 13:38:38 BST 2005


On Thu, 31 Mar 2005, Andrew J. Schorr wrote:

> The current code is sloppy with respect to the way it manages
> interface name length issues and whether they are NUL-terminated
> or implicitly terminated at INTERFACE_NAMSIZ characters.

Well, AIUI:

- the string should be no more than INTERFACE_NAMSIZ
   - its the largest known length of interface name on any platform we
     support
- the storage for the string should be INTERFACE_NAMSIZ+1
- hence we should truncate strings at INTERFACE_NAMSIZ
- storage of string should set string[INTERFACE_NAMSIZ] = '\0' for
   safety, however:
   - kernel interfaces do not need nul terminator
   - zserv protocol is not null terminated

Seem right?

> For example, this seems bad:
>
> ti58-quagga# config term
> ti58-quagga(config)# interface reallylonginterfacename0
> ti58-quagga(config-if)# desc test
>
> ti58-quagga# show interface
> ...
> Interface reallylonginterfacen is down
>  Description: test
>  index -1 inactive interface
>
> The name is being silently truncated.

Seems roughly right, we cant support arbitrary length interface 
names, even if we did kernel's usually dont. The only possible 
confusion is here that kernel may have a smaller interface name size 
and that it will truncate the name to an even smaller one.

> The API makes the mistake of having lots of functions that make 
> assumptions about string lengths, instead of just taking explicit 
> length arguments.

Defining interface name in terms of string,length and getting rid of 
INTERFACE_NAMSIZE might be even better, yes.

> In practice this may not matter much, but the current coding style 
> is not robust at all.  One possible fix is to change the 
> if_lookup_by_name and if_get_by_name functions (and any other 
> functions that take interface names as arguments) to take 
> additional explicit length arguments that will force calling code 
> to expose their assumptions.  Or we could try to make sure that all 
> interface names are passed around with a terminating NUL 
> character...

But if_create sets a terminator. Where is ifname created without a 
terminator?

> Regards,
> Andy

regards,
-- 
Paul Jakma	paul at clubi.ie	paul at jakma.org	Key ID: 64A2FF6A
Fortune:
They are called computers simply because computation is the only significant
job that has so far been given to them.



More information about the Quagga-dev mailing list