Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 212850 | Differences between
and this patch

Collapse All | Expand All

(-)src/npw-viewer.orig (-20 / +56 lines)
Lines 28-33 Link Here
28
#include <dlfcn.h>
28
#include <dlfcn.h>
29
#include <unistd.h>
29
#include <unistd.h>
30
#include <errno.h>
30
#include <errno.h>
31
#include <sys/types.h>
32
#include <sys/wait.h>
31
33
32
#include <X11/X.h>
34
#include <X11/X.h>
33
#include <X11/Xlib.h>
35
#include <X11/Xlib.h>
Lines 3199-3232 int main(int argc, char **argv) Link Here
3199
	  --argc;
3201
	  --argc;
3200
  }
3202
  }
3201
3203
3204
3202
  // Open plug-in and get exported lib functions
3205
  // Open plug-in and get exported lib functions
3203
  void *handle = NULL;
3206
  void *handle = NULL;
3207
#define EXIT_TRUE  0
3208
#define EXIT_FALSE 1
3209
3204
  if (plugin_path == NULL)
3210
  if (plugin_path == NULL)
3205
	cmd = CMD_HELP;
3211
	cmd = CMD_HELP;
3206
  else {
3212
  else {
3213
  	pid_t pid;
3207
	const char *error;
3214
	const char *error;
3208
	D(bug("  %s\n", plugin_path));
3215
	D(bug("  %s\n", plugin_path));
3209
	if ((handle = dlopen(plugin_path, RTLD_LAZY)) == NULL) {
3216
3210
	  npw_printf("ERROR: %s\n", dlerror());
3217
	/* test opening the libary in a child process to prevent a dodgy libary crashing app */
3211
	  return 1;
3218
	if(0 > (pid = fork()))
3212
	}
3219
		return 1;
3213
	dlerror();
3220
3214
	g_plugin_NP_GetMIMEDescription = (NP_GetMIMEDescriptionUPP)dlsym(handle, "NP_GetMIMEDescription");
3221
	/* IN Child */
3215
	if ((error = dlerror()) != NULL) {
3222
	if(!pid) {
3216
	  npw_printf("ERROR: %s\n", error);
3223
		/* this line may throw SIGSEGV */
3217
	  return 1;
3224
		if(NULL == (handle = dlopen(plugin_path, RTLD_LAZY)))
3218
	}
3225
			exit(EXIT_FALSE);
3219
	g_plugin_NP_Initialize = (NP_InitializeUPP)dlsym(handle, "NP_Initialize");
3226
3220
	if ((error = dlerror()) != NULL) {
3227
		dlclose(handle);
3221
	  npw_printf("ERROR: %s\n", error);
3228
		exit(EXIT_TRUE );
3222
	  return 1;
3229
	}
3223
	}
3230
	else {
3224
	g_plugin_NP_Shutdown = (NP_ShutdownUPP)dlsym(handle, "NP_Shutdown");
3231
		/* parent */
3225
	if ((error = dlerror()) != NULL) {
3232
		int status;
3226
	  npw_printf("ERROR: %s\n", error);
3233
		if(0 >(pid = waitpid(pid,&status,0)))
3227
	  return 1;
3234
			return 1;
3235
3236
		if(status != EXIT_TRUE)
3237
			return 1;
3238
	
3239
		/* dlopen() will not seqfault, should be good to go */
3240
		if ((handle = dlopen(plugin_path, RTLD_LAZY)) == NULL) {
3241
		  npw_printf("ERROR: %s\n", dlerror());
3242
		  return 1;
3243
		}
3244
		dlerror();
3245
		g_plugin_NP_GetMIMEDescription = (NP_GetMIMEDescriptionUPP)dlsym(handle, "NP_GetMIMEDescription");
3246
		if ((error = dlerror()) != NULL) {
3247
	  		npw_printf("ERROR: %s\n", error);
3248
	  		return 1;
3249
		}
3250
		g_plugin_NP_Initialize = (NP_InitializeUPP)dlsym(handle, "NP_Initialize");
3251
		if ((error = dlerror()) != NULL) {
3252
	  		npw_printf("ERROR: %s\n", error);
3253
	 		 return 1;
3254
		}
3255
		g_plugin_NP_Shutdown = (NP_ShutdownUPP)dlsym(handle, "NP_Shutdown");
3256
		if ((error = dlerror()) != NULL) {
3257
	  		npw_printf("ERROR: %s\n", error);
3258
	  		return 1;
3259
		}
3260
		g_plugin_NP_GetValue = (NP_GetValueUPP)dlsym(handle, "NP_GetValue");
3228
	}
3261
	}
3229
	g_plugin_NP_GetValue = (NP_GetValueUPP)dlsym(handle, "NP_GetValue");
3262
  
3230
  }
3263
  }
3231
3264
3232
  int ret = 1;
3265
  int ret = 1;
Lines 3249-3251 int main(int argc, char **argv) Link Here
3249
	dlclose(handle);
3282
	dlclose(handle);
3250
  return ret;
3283
  return ret;
3251
}
3284
}
3285
3286
3287

Return to bug 212850