[PATCH] Fix the FreeBSD build

Jeremy Allison jra at samba.org
Wed Jun 7 20:33:07 UTC 2017


On Wed, Jun 07, 2017 at 01:07:39PM -0700, Jeremy Allison via samba-technical wrote:
> On Thu, Jun 08, 2017 at 07:47:49AM +1200, Andrew Bartlett wrote:
> > On Wed, 2017-06-07 at 10:17 -0700, Jeremy Allison wrote:
> > > On Wed, Jun 07, 2017 at 10:09:50PM +1200, Andrew Bartlett via samba-technical wrote:
> > > >  }
> > > > +#elif (!defined(STRERROR_R_XSI_NOT_GNU))
> > > > +#undef strerror_r
> > > > +int rep_strerror_r(int errnum, char *buf, size_t buflen)
> > > > +{
> > > > +	char *s = strerror_r(errnum, buf, buflen);
> > > > +	if (s == NULL) {
> > > > +		/* Shouldn't happen, should always get a string */
> > > > +		return EINVAL;
> > > > +	} else if (s != buf) {
> > > > +		strlcpy(buf, s, buflen);
> > > > +		if (strlen(s) > buflen - 1) {
> > > > +			return ERANGE;
> > > > +		}
> > > 
> > > Minor nit - the ERANGE check should be *before*
> > > the strlcpy, that way we don't touch *buf if we're
> > > returning an error.
> > 
> > It was deliberate, but I've not checked the actual behaviour of the
> > official call and the manpage is unclear which has precedence.  
> 
> Yeah I'm pretty sure that behavior (writing into *buf on ERANGE)
> is wrong though. "Thou shalt never mess with args on error" is
> pretty baked into POSIX :-).
> 
> > Could you do that, as sadly this is becoming a massive time sink at
> > this point, and Volker's 'just give up and go back to strerror()' patch
> > is already in?
> > 
> > The untested idea was that it would always write something, as error
> > checking by callers of strerror_r seems unlikely, and not initialising
> > the buffer seems even less expected. 
> 
> I'll take a look.

Wow, after checking with a test case I'm completely wrong !

At least the glibc implementation scribbles on the buffer when
returning ERANGE. Colour me *extremly* surprised !

Your implementation is correct here, thanks for getting me
to check.



More information about the samba-technical mailing list