The MPLS WG Archive

Cell Relay Retreat>MPLS WG Archive>month:2003-May> msg00064



[Date Prev][Date Next][Thread Prev][Thread Next]  
  [Date Index][Thread Index][Author Index][Subject Index]

Question regarding null padding session name in RSVP-TE Att obj

  • From: David Charlap <David.Charlap@marconi.com>
  • Date: Fri, 16 May 2003 14:22:42 -0400
  • Organization: Marconi, Vienna VA
  • User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4b) Gecko/20030430

Jiang, Donghua (Jane) wrote:
> 
> 2) Should we use the Name Length to decide where the end of the Session Name is, rather than checking on whether the character is printable or not?

Yes, you absolutely must.

The RFC says that the object is NULL padded, it does not say that the 
string is NULL terminated.  This means that if the name is an exact 
multiple of 4 bytes, there may not be any trailing NULL.  If you use a 
function that expects a NULL-terminated string (like the C language 
strcpy function), it may overrun the end fo the string, resulting in 
undefined behavior.

Also note that the RFC doesn't specify ASCII (or any other encoding) for 
the name.  If the encoding is something that permits zero-byte values 
(e.g. Unicode), a function designed for NULL-terminated strings may get 
a short count of bytes.

In other words, this is a counted string and should be treated as such. 
  If use use the C language, you should not use string functions on it. 
  Instead, track the length and use functions like memcpy to copy its 
value.  If you absolutely must pass it to a function that uses 
null-terminated strings, make sure to append your own NULL character to 
guarantee that the function doesn't overrun the end of the string.

-- David