public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/1377] New: seg fault inside getwc() when using LD_PRELOADed code
@ 2005-09-23 22:09 manuelarriaga at gmail dot com
  2005-09-23 22:23 ` [Bug libc/1377] " jakub at redhat dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: manuelarriaga at gmail dot com @ 2005-09-23 22:09 UTC (permalink / raw)
  To: glibc-bugs

A segmentation fault occurs inside getwc() if this function is called on a file
pointer obtained from a preloaded fopen() which merely returns the (FILE*)
pointer returned by the glibc fopen().

System: Linux kernel 2.6.11.4, gcc 3.3.4

To replicate:

1) compile the following code snippet

/*

Compiled with 

gcc -Wall -W -D_REENTRANT libtest.c -nostartfiles -shared -fPIC
-Wl,-soname,libtest.so -o libtest.so -ldl
 * 
 */

#define _GNU_SOURCE

#include <stdio.h>
#include <dlfcn.h>

FILE *fopen(const char *path, const char *mode)
{
   FILE * (*real_fopen) (const char*,const char*);
   
   real_fopen = dlsym(RTLD_NEXT, "fopen");
   
   if (!real_fopen)
     {
        printf("dlsym() failed\n.");
        return NULL;
     }

   printf("invoking real fopen\n");
   return (*real_fopen)(path,mode);
}


2) compile the following test program

/* 

Compiled with

gcc -o test test.c

*/

#include <stdio.h>
#include <wchar.h>

int main (void) 
{
   
   FILE *fp = fopen("abcd", "r");

   if (!fp)
     {
        printf("inside test program: fp == NULL, quitting.\n");
        return 0;
     }
   
   wint_t w = getwc(fp);
   return 0;
}

3) run

LD_PRELOAD=./libtest.so ./test

This generates a segmentation fault inside getwc().

-- 
           Summary: seg fault inside getwc() when using LD_PRELOADed code
           Product: glibc
           Version: 2.3.4
            Status: NEW
          Severity: critical
          Priority: P1
         Component: libc
        AssignedTo: gotom at debian dot or dot jp
        ReportedBy: manuelarriaga at gmail dot com
                CC: glibc-bugs at sources dot redhat dot com,manuelarriaga
                    at gmail dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://sourceware.org/bugzilla/show_bug.cgi?id=1377

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-11-14 11:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-23 22:09 [Bug libc/1377] New: seg fault inside getwc() when using LD_PRELOADed code manuelarriaga at gmail dot com
2005-09-23 22:23 ` [Bug libc/1377] " jakub at redhat dot com
2005-09-23 22:35 ` manuelarriaga at gmail dot com
2009-11-12 21:46 ` kkylheku at gmail dot com
2009-11-12 22:06 ` kkylheku at gmail dot com
2009-11-13  0:25 ` kkylheku at gmail dot com
2009-11-13 18:50 ` pasky at suse dot cz
2009-11-14  3:49 ` kkylheku at gmail dot com
2009-11-14 11:08 ` pasky at suse dot cz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).