On 26/04/06, Nils Larsch <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Revision: 2914
> > Author: aj
> > Date: 2006-04-26 10:08:09 +0000 (Wed, 26 Apr 2006)
> >
> > Log Message:
> > -----------
> > make sure buffer is 0 terminated.
> >
> > Modified Paths:
> > --------------
> > releases/opensc-0.11.0/src/libopensc/log.c
> > Modified: releases/opensc-0.11.0/src/libopensc/log.c
> > ===================================================================
> > --- releases/opensc-0.11.0/src/libopensc/log.c 2006-04-26 10:08:00
> > UTC (rev 2913)
> > +++ releases/opensc-0.11.0/src/libopensc/log.c 2006-04-26 10:08:09
> > UTC (rev 2914)
> > @@ -98,8 +98,8 @@
> > }
> >
> > if (file != NULL) {
> > - r = snprintf(buf, sizeof(buf), "%s:%d:%s: ", file, line, func
> > ? func : "");
> > - if (r < 0 || (unsigned int)r > sizeof(buf))
> > + r = snprintf(buf, sizeof(buf)-1, "%s:%d:%s: ", file, line,
> > func ? func : "");
>
> unless I've overlooked something I can't see a problem with the old code.
> According to
> http://www.opengroup.org/onlinepubs/000095399/functions/printf.html
> or the snprintf manpage on my system snprintf() prints at most "sizeof(buf)-1"
> characters != '\0' so the old code should work ...
I agree with Nils. According to my manpages "The functions snprintf
and vsnprintf do not write more than size bytes (including the
trailing '\0')."
Can you revert the change Andreas?
It is really a bad choice that strncpy(3) does not also include the
null byte, and that strncat(3) uses at most n+1 bytes always including
the null byte.
Bye,
--
Dr. Ludovic Rousseau
_______________________________________________
opensc-devel mailing list
[email protected]
http://www.opensc-project.org/mailman/listinfo/opensc-devel