From owner-freebsd-questions@FreeBSD.ORG Mon Jul 19 17:55:51 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A05D5106566C for ; Mon, 19 Jul 2010 17:55:51 +0000 (UTC) (envelope-from bonomi@mail.r-bonomi.com) Received: from mail.r-bonomi.com (ns2.r-bonomi.com [204.87.227.129]) by mx1.freebsd.org (Postfix) with ESMTP id 585CD8FC15 for ; Mon, 19 Jul 2010 17:55:50 +0000 (UTC) Received: (from bonomi@localhost) by mail.r-bonomi.com (8.14.3/rdb1) id o6JHtFKY028398; Mon, 19 Jul 2010 12:55:15 -0500 (CDT) Date: Mon, 19 Jul 2010 12:55:15 -0500 (CDT) From: Robert Bonomi Message-ID: <201007191755.o6JHtFKY028398@mail.r-bonomi.com> To: freebsd-questions@freebsd.org Subject: Re: Has anybody got a *working* example of getpwnam_r() ?? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Jul 2010 17:55:51 -0000 > Date: Mon, 19 Jul 2010 01:13:25 -0400 > From: Brad Mettee > 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. ) > 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.