@@ -72,24 +72,60 @@ static char *getLibtoolVer(const char *filename)
7272 }
7373 break ;
7474 } else {
75- return NULL ;
75+ break ;
7676 }
7777 }
7878 return NULL ;
7979}
8080
81+ /*
82+ * Rather than re-implement path searching for shared objects, use
83+ * dlmopen(). This will still perform initialization and finalization
84+ * functions, which isn't necessarily safe, so do that in a separate
85+ * process.
86+ */
8187static char * getLibtoolVerFromShLink (const char * filename )
8288{
83- void * dl_handle ;
84- struct link_map * linkmap ;
85- char * version = NULL ;
86- dl_handle = dlmopen (LM_ID_NEWLM , filename , RTLD_LAZY );
87- if (dl_handle == NULL ) return NULL ;
88- if (dlinfo (dl_handle , RTLD_DI_LINKMAP , & linkmap ) != -1 ) {
89- version = getLibtoolVer (linkmap -> l_name );
89+ char dest [PATH_MAX ];
90+ int pipefd [2 ];
91+ pid_t cpid ;
92+
93+ if (pipe (pipefd ) == -1 ) {
94+ return NULL ; // Should this be a fatal error instead?
95+ }
96+ cpid = fork ();
97+ if (cpid == -1 ) {
98+ return NULL ; // Should this be a fatal error instead?
99+ }
100+ if (cpid == 0 ) {
101+ void * dl_handle ;
102+ struct link_map * linkmap ;
103+ char * version = NULL ;
104+
105+ close (pipefd [0 ]);
106+ dl_handle = dlmopen (LM_ID_NEWLM , filename , RTLD_LAZY );
107+ if (dl_handle == NULL ) _exit (0 );
108+ if (dlinfo (dl_handle , RTLD_DI_LINKMAP , & linkmap ) != -1 ) {
109+ version = getLibtoolVer (linkmap -> l_name );
110+ }
111+ write (pipefd [1 ], version , strlen (version ));
112+ close (pipefd [1 ]);
113+ free (version );
114+ dlclose (dl_handle );
115+ _exit (0 );
116+ } else {
117+ ssize_t len ;
118+ close (pipefd [1 ]);
119+ dest [0 ] = 0 ;
120+ len = read (pipefd [0 ], dest , sizeof (dest ));
121+ if (len > 0 ) dest [len ] = 0 ;
122+ close (pipefd [0 ]);
123+ wait (NULL );
90124 }
91- dlclose (dl_handle );
92- return version ;
125+ if (strlen (dest ) > 0 )
126+ return strdup (dest );
127+ else
128+ return NULL ;
93129}
94130
95131/*
0 commit comments