[PATCH v4] ungetc: Guarantee single char pushback

Maciej W. Rozycki macro@redhat.com
Mon Dec 16 16:16:57 GMT 2024


On Mon, 16 Dec 2024, Siddhesh Poyarekar wrote:

> > > > +
> > > > +void *
> > > > +malloc (size_t sz)
> > > > +{
> > > > +  if (fail)
> > > > +    return NULL;
> > > > +
> > > > +  return __libc_malloc (sz);
> > > > +}
> > > 
> > >   OK, this interposes `malloc' so as to conditionally induce a failure and
> > > refers to `__libc_malloc' if the condition does not stand.  A bit hackish
> > > IMO, but we're in control here, so let it be.
> > > 
> > >   I think this function deserves an introductory comment, even if a single
> > > terse line.
> > 
> > OK.
> > 
> 
> I just realized while adding the comment that the reason why I was using
> __libc_malloc (which was to avoid dlsym) was a flimsy one and will in fact end
> up skipping any interposed malloc implementations.  It's not an immediate
> problem since I don't think anybody runs the testsuite with interposed malloc
> today, but I'll use dlsym anyway to be future-proof.

 But is using `dlsym' going to actually work?

 AFAIK a symbol in the main executable pre-empts any other ones of the 
same name coming from the loader's initial namespace (i.e. including any 
pulled early via LD_PRELOAD, but not those loaded via `dlopen' into a new 
namespace).

 NB we have a preexisting use of `__libc_malloc' in another test case, so 
if coming up with an alternative arrangement, I suggest to cover it too.

  Maciej



More information about the Libc-alpha mailing list