GNU bug report logs -
#21065
Small bug in touch
Previous Next
Full log
Message #33 received at 21065 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
[adding the list back in, with permission]
On 07/14/2015 07:47 PM, Vinh Nguyen wrote:
> Dear Eric,
> Thank you for your useful information about dirname function. But the main thing I wanted to report is not the way to use dirname, but the weird behavior of dirname loading library named "." into the running process and cause error "Error while mapping shared library sections. '.' is not in executable format: Is a directory" and segmentation fault subsequently. The document says nothing about this behavior so it is a bug. Also, Dl_info's dli_fname is a char array, not const char* so the cast in "dirname((char*)info.dli_fname)" just do nothing.
> I'm looking forward to hearing from you soon.
Your problem stems from the fact that calling dirname() modifies its
argument.
>> Dl_info info;
>> if ( dladdr( ( const void* )function_to_get_address, &info ) == 0 )
>> return false;
>> if ( info.dli_fname == NULL )
>> return false;
>> dirname((char*)info.dli_fname); (1)
Whatever info.dli_fname was prior to dirname, it was modified in place
to now be "." after the invalid call. So now that it has a changed
value, it is messing with all the assumptions of the rest of dl*() that
assume the name will not be changed.
I stand by my assertion that the bug is in your invalid use of dirname().
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
This bug report was last modified 10 years and 6 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.