Update of /export/home/ntop/ntop
In directory unknown:/tmp/cvs-serv8670

Modified Files:
        globals-core.h 
Log Message:

It turns out that the much loved construct,

if(snprintf(....) < 0) BufferTooShort();

is flawed for recent glibc libraries.  Quoting (Linux - RH9) man snprintf:

   Return value
       Upon successful return, these functions return the number of characters
       printed  (not  including  the  trailing  '\0' used  to  end  output to
       strings).  The functions snprintf and vsnprintf do not write more  than
       size  bytes (including the trailing '\0').  If the output was truncated
       due to this limit then the return value is  the  number  of  characters
       (not  including the trailing '\0') which would have been written to the
       final string if enough space had been available. Thus, a  return  value
       of  size  or  more means that the output was truncated. (See also below
       under NOTES.)  If an output error is encountered, a negative  value  is
       returned.
...
NOTES
       The  glibc  implementation of the functions snprintf and vsnprintf con-
       forms to the C99 standard, i.e.,  behaves  as  described  above,  since
       glibc version 2.1. Until glibc 2.0.6 they would return -1 when the out-
       put was truncated.



This large patch replaces that logic by a routine (actually a macro):

safe_snprintf()

which handles BOTH cases and automatically logs the error message, including
the file/line and minimum required size (glibc >= 2.1):

  **ERROR** Buffer too short @ xxxxxxxxxx.c:3728 (increase to at least 25) 

One difference - since it's a macro, you can not code

safe_snprintf(...
#ifdef WIN32
#else
#endif
    );

instead the #ifdef needs to completely surround the macro:

#ifdef WIN32
safe_snprintf(...);
#else
safe_snprintf(...);
#endif

For cases where you genuinely need to old behavior (i.e. not a snprintf()), 
a new BufferTooSmall() macro replaces BufferTooShort().



If you find problems, report them to the ntop-dev list.  Thanks!



The development of this function was partly sponsored by an international
organization which wishes to remain anonymous.

-----Burton



_______________________________________________
Ntop-dev mailing list
[EMAIL PROTECTED]
http://listgateway.unipi.it/mailman/listinfo/ntop-dev

Reply via email to