[Date Prev][Date Next] [Chronological] [Thread] [Top]

RE: non-EBCDIC ber_pvt_vsnprintf is not portable (ITS#2128)



> -----Original Message-----
> From: owner-openldap-bugs@OpenLDAP.org
> [mailto:owner-openldap-bugs@OpenLDAP.org]On Behalf Of
> dsr+ldap@mail.lns.cornell.edu

> Full_Name: Dan Riley
> Version: 2.1.5
> OS: Tru64 4.0F
> URL: ftp://ftp.openldap.org/incoming/
> Submission from: (NULL) (128.84.46.236)
>
>
> ber_pvt_vsnprintf always returns an empty string on Tru64
> 4.0F.  This is
> entirely consistent with ANSI/ISO 9899-1990 (ANSI C 89) and
> SUSv2, which say (of
> the buffer passed to setvbuf) that "the contents of the array
> at any time are
> indeterminate", which means passing a buffer to setvbuf
> cannot be used for
> formatting.  The enclosed patch makes ber_pvt_vsnprintf
> portable (as long as
> vsprintf is available), at the cost of repeating the formatting:
>
> --- libraries/liblber/stdio.c~  Tue Sep 17 10:35:52 2002
> +++ libraries/liblber/stdio.c   Sun Oct  6 15:16:17 2002
> @@ -55,6 +55,9 @@
>
>         fclose( f );
>         signal( SIGPIPE, sig );
> +       if ( res > 0 && res < n ) {
> +               res = vsprintf( str, fmt, ap );
> +       }
>         return res;
>  }
>  #endif
>
Thanks for pointing this out. There's more problems lurking here, as
ber_pvt_vsnprintf was written according to the old definition of snprintf.
I.e., it returns -1 on buffer overflow. The C99 definition says it should
return the total number of characters that would have been printed, had the
buffer been large enough. We'll have to do an audit to see if anyone is
actually relying on the return value of snprintf and fix those areas as well.

  -- Howard Chu
  Chief Architect, Symas Corp.       Director, Highland Sun
  http://www.symas.com               http://highlandsun.com/hyc
  Symas: Premier OpenSource Development and Support