On Tuesday 08 December 2009 16:07:42 Josh Fisher wrote:
> Kern Sibbald wrote:
> > Hello,
> >
> > Yesterday was an unusually good day for bugs (others may call it a bad
> > day). Two Bacula crashes showed up in the Bacula regressions. Thanks
> > regression testers. :-( The first one is an SD race condition. It was
> > automatically identified by Eric's thread deadlock detection code -- good
> > going Eric. I have not yet fixed it -- it will need more reflection as it
> > is a non-trivial conceptial problem.
> >
> > The second one was in bstrncat() -- really ugly, because it trashes
> > memory under certain conditions :-(  This one should now be fixed (it is
> > in the git repo).  We will probably back port it.  This one is a lesson
> > in how Kern has misunderstood the Unix definition of strncat() for almost
> > 40
> > years!!!  :-(  :-(
>
> Out of curiosity, what was the misunderstanding? 

Tricky -- at least for me ...

> Is it that strncat() 
> can write n+1 chars instead of n (like the other strn* functions)?

No, the Unix definition of strncat(char *dest, const char *src, size_t n); is 
that a maximum of n characters may be transferred from src to dest.  Thus n 
serves no use in ensuring that the size of dest is not exceeded.  This is not 
very logical to me and is not the way I would have implemented the function.

I believed that n-1 was the maximum number of characters total that dest could 
hold.  This is what bstrncat() was supposed to do.  The bacula function is 
now "correctly" implemented according to what I think is much more useful and 
logical.

The old manpage for strcat correctly states the implementation, but I did not 
read it attentively enough some years ago (this manpage is still in SuSE 
10.2).   A more recent manpage (with a lot of additions) available on my 
Ubuntu system makes it pretty clear how the function behaves.

I wonder how many other programmers misunderstand the behavior of strncat().

Regards,

Kern

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Bacula-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bacula-devel

Reply via email to