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

(-)npw-config.c.orig (-33 / +78 lines)
Lines 233-238 static const char **get_mozilla_plugin_d Link Here
233
  const int n_default_dirs = (sizeof(default_dirs) / sizeof(default_dirs[0]));
233
  const int n_default_dirs = (sizeof(default_dirs) / sizeof(default_dirs[0]));
234
  const char **dirs = malloc((n_default_dirs + 2) * sizeof(dirs[0]));
234
  const char **dirs = malloc((n_default_dirs + 2) * sizeof(dirs[0]));
235
  int i, j;
235
  int i, j;
236
  
237
  if(!dirs)
238
  {
239
	printf("\nFailed to alloc dirs");
240
	exit(EXIT_FAILURE);
241
  }
242
  
236
  for (i = 0, j = 0; i < n_default_dirs; i++) {
243
  for (i = 0, j = 0; i < n_default_dirs; i++) {
237
	const char *dir = default_dirs[i];
244
	const char *dir = default_dirs[i];
238
	if (dir && access(dir, F_OK) == 0)
245
	if (dir && access(dir, F_OK) == 0)
Lines 601-613 static bool is_wrapper_plugin_handle(voi Link Here
601
608
602
static bool is_wrapper_plugin(const char *plugin_path, NPW_PluginInfo *out_plugin_info)
609
static bool is_wrapper_plugin(const char *plugin_path, NPW_PluginInfo *out_plugin_info)
603
{
610
{
604
  void *handle = dlopen(plugin_path, RTLD_LAZY);
611
pid_t pid;
605
  if (handle == NULL)
612
#define EXIT_TRUE  0
606
	return false;
613
#define EXIT_FALSE 1
614
615
	if(0 > (pid = fork()))
616
		return false;
617
618
	/* IN Child */
619
	if(!pid)
620
	{
621
		/* test the libary in a child process to prevent a dodgy libary crashing app */
622
		void *handle;
623
		bool ret;
624
		/* this line may throw SIGSEGV */
625
		if(NULL == (handle = dlopen(plugin_path, RTLD_LAZY)))
626
			exit(EXIT_FALSE);
627
628
  		ret = is_wrapper_plugin_handle(handle, out_plugin_info);
629
		dlclose(handle);
630
		exit( (ret) ? EXIT_TRUE : EXIT_FALSE );
631
	}
632
	else
633
	{
634
		int status;
635
		if(0 >(pid = waitpid(pid,&status,0)))
636
			return false;
607
637
608
  bool ret = is_wrapper_plugin_handle(handle, out_plugin_info);
638
		return (status == EXIT_TRUE) ;
609
  dlclose(handle);
639
	}
610
  return ret;
611
}
640
}
612
641
613
static bool is_wrapper_plugin_0(const char *plugin_path)
642
static bool is_wrapper_plugin_0(const char *plugin_path)
Lines 643-678 static bool is_system_wide_wrapper_plugi Link Here
643
672
644
typedef bool (*is_plugin_cb)(const char *plugin_path, NPW_PluginInfo *plugin_info);
673
typedef bool (*is_plugin_cb)(const char *plugin_path, NPW_PluginInfo *plugin_info);
645
typedef int (*process_plugin_cb)(const char *plugin_path, NPW_PluginInfo *plugin_info);
674
typedef int (*process_plugin_cb)(const char *plugin_path, NPW_PluginInfo *plugin_info);
675
static int process_entry(struct dirent *ent,const char *plugin_dir,is_plugin_cb test, process_plugin_cb process);
646
676
647
static int process_plugin_dir(const char *plugin_dir, is_plugin_cb test, process_plugin_cb process)
677
static int process_plugin_dir(const char *plugin_dir, is_plugin_cb test, process_plugin_cb process)
648
{
678
{
649
  if (g_verbose)
679
	DIR    		*dir; 
650
	printf("Looking for plugins in %s\n", plugin_dir);
680
	struct dirent   *ent;	
651
681
	
652
  DIR *dir = opendir(plugin_dir);
682
	if( !plugin_dir || !test || !process) 
653
  if (dir == NULL)
683
  		return -1;
654
	return -1;
684
	
655
685
	if(g_verbose)
656
  int plugin_path_length = 256;
686
		printf("\nLooking for plugins in %s\n", plugin_dir);
657
  char *plugin_path = (char *)malloc(plugin_path_length);
687
	
658
  int plugin_dir_length = strlen(plugin_dir);
688
	if( ! (dir = opendir(plugin_dir))) 
659
689
		return 1;
660
  struct dirent *ent;
690
  	
661
  while ((ent = readdir(dir)) != NULL) {
691
 	while(NULL != (ent = readdir(dir)))
662
	int len = plugin_dir_length + 1 + strlen(ent->d_name) + 1;
692
		if( process_entry(ent,plugin_dir,test,process) ) {
663
	if (len > plugin_path_length) {
693
			closedir(dir);
664
	  plugin_path_length = len;
694
			return -1;
665
	  plugin_path = (char *)realloc(plugin_path, plugin_path_length);
695
		}
666
	}
696
	closedir(dir);
667
	sprintf(plugin_path, "%s/%s", plugin_dir, ent->d_name);
697
	return 0;
668
	NPW_PluginInfo plugin_info;
669
	if (test(plugin_path, &plugin_info))
670
	  process(plugin_path, &plugin_info);
671
  }
672
673
  free(plugin_path);
674
  closedir(dir);
675
  return 0;
676
}
698
}
677
699
678
static int do_install_plugin(const char *plugin_path, const char *plugin_dir, NPW_PluginInfo *plugin_info)
700
static int do_install_plugin(const char *plugin_path, const char *plugin_dir, NPW_PluginInfo *plugin_info)
Lines 1089-1091 int main(int argc, char *argv[]) Link Here
1089
1111
1090
  return 0;
1112
  return 0;
1091
}
1113
}
1114
1115
static int process_entry(struct dirent *ent,const char *plugin_dir,is_plugin_cb test, process_plugin_cb process)
1116
{
1117
	NPW_PluginInfo  plugin_info = {{0}} ;
1118
	int len,tot;
1119
	char *p;
1120
1121
	if(!ent || !plugin_dir || !test || !process )
1122
		return -1;
1123
	
1124
	if(!(p = malloc((len = strlen(ent->d_name) + strlen(plugin_dir) + 5))))
1125
		return -1;
1126
	
1127
	tot = snprintf(p,len-1, "%s/%s", plugin_dir, ent->d_name);
1128
  	p[tot] = '\0';
1129
1130
        if(test(p, &plugin_info))
1131
		process(p, &plugin_info);
1132
	free(p);
1133
	return 0;
1134
}
1135
1136

Return to bug 212850