[PATCH] Fix the FreeBSD build

Andrew Bartlett abartlet at samba.org
Wed Jun 7 19:47:49 UTC 2017


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.  

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. 

Thanks,

Andrew Bartlett

-- 
Andrew Bartlett                       http://samba.org/~abartlet/
Authentication Developer, Samba Team  http://samba.org
Samba Developer, Catalyst IT          http://catalyst.net.nz/services/samba




More information about the samba-technical mailing list