Has anybody got a *working* example of getpwnam_r() ??
Robert Bonomi
bonomi at mail.r-bonomi.com
Mon Jul 19 17:55:51 UTC 2010
> Date: Mon, 19 Jul 2010 01:13:25 -0400
> From: Brad Mettee <bmettee at pchotshots.com>
> Subject: Re: Has anybody got a *working* example of getpwnam_r() ??
>
> Robert Bonomi wrote:
> > I've _got_ to be doing something wrong, sine I'm getting heap corruption
> > calling it. But for the life of me, I can't figure out -what- is wrong.
[[.. sniparoo ..]]
> >
> >
> > the offending call is :
> >
> > getpwnam_r(cp3, &pw_data, buffer2, sizeof(buffer2), &pwd);
> >
> > data declaration at the beginning of the function:
> > char buffer[1024];
> > char buffer2[1024];
> > char mailbox[1024];
> > *cp,*cp2,*cp3,*cp4 = buffer;
> > struct passwd pw_data,pw_data2,*pwd=&pw_data2;
> > int i;
> >
[[.. sneck gory details ..]]
> >
> > anybody got _any_ ideas?
> >
> This might help.
>
> Just above the crashing call, open a file, and dump the contents of the
> vars you're sending to the function with fprintf, then close the file.
I've verified everything with GDB immediately before the getwpnam_r() call.
everyting is what I expect -- cp3 points to 'buffer' (*not* 'buffer2', the
scratchpad buffer for the function) which has a valid username in it. (gdb
instruction 'p *cp3' returns "bonomi")
And I checked things immediately _after_ the getpwnam_r() call. heap (not
stack) corruption, out of the blue, at a CONSTANT location, regardless of
changes to the input variables (value _or_ location).
> I
> suspect cp3 doesn't point to valid data and is causing the function call
> to fail (it looks like it's pointing to the same thing as buffer, which
> doesn't look like how the function should be called). Having the
> contents of the individual vars will help you narrow down exactly what's
> occuring. Data you want to see is the pointers themselves, and maybe the
> first 8 or so characters of data that it's pointing to.
BTDT, GTTS. no joy.
The call returns, signalling "no error" (return value zero), pw_data is
filled in with the correct user information, and pwd is set to the address
of (the passed-in parameter) pw_data. Everything is as it should be
on a successful call -- *EXCEPT* for the unexpected corruption of the heap.
I"m in the position of His Majesty in 'The King and I'.
I quote: "Tis a *PUZZLEMENT*!!" (emphasis added. <wry grin>)
> And if this doesn't help, there's always Google CodeSearch
> http://www.google.com/codesearch , for examples of how to call it.
I apparently don't know how to use codesearch. All I get is various
source-code for the function itself, not a 'how to use' illustration.
Appreciate the thoughts.
I'll re-iterate my query -- does anybody have a _working_ example _ON_FREEBSD_
of getpwnam_r() ??
I'm about at my wit's end -- short of re-compiling libc with a '-g', so I can
trace through the library calls, and see what's happening 'underneath the
covers', I can't thing of anything else to try.
More information about the freebsd-questions
mailing list