Sophie

Sophie

distrib > Mandriva > 2009.0 > x86_64 > by-pkgid > 8604cbc4d16ebbba706929d8df6004ee > files > 3

nspluginwrapper-1.1.0-7mdv2009.0.src.rpm

diff -up nspluginwrapper-1.1.0/src/npw-viewer.c.fork nspluginwrapper-1.1.0/src/npw-viewer.c
--- nspluginwrapper-1.1.0/src/npw-viewer.c.fork	2008-07-08 14:23:26.000000000 +0200
+++ nspluginwrapper-1.1.0/src/npw-viewer.c	2008-07-08 14:26:58.000000000 +0200
@@ -67,6 +67,20 @@
 // RPC global connections
 rpc_connection_t *g_rpc_connection attribute_hidden = NULL;
 
+// Viewer orignal pid - check against incorrect plugins
+pid_t viewer_pid = 0;
+
+// Pid support routines
+void pid_set(void)
+{
+  viewer_pid = getpid();
+}
+
+int pid_check(void)
+{
+  return(viewer_pid == getpid());
+}
+
 // Instance state information about the plugin
 typedef struct _PluginInstance {
   NPP instance;
@@ -581,6 +595,9 @@ static void
 g_NPN_ForceRedraw(NPP instance)
 {
   D(bug("NPN_ForceRedraw instance=%p\n", instance));
+	
+  if(!pid_check())
+	return NPERR_INVALID_INSTANCE_ERROR;
 
   UNIMPLEMENTED();
 }
@@ -615,9 +632,11 @@ invoke_NPN_GetURL(NPP instance, const ch
 static NPError
 g_NPN_GetURL(NPP instance, const char *url, const char *target)
 {
+  if(!pid_check())
+	return NPERR_INVALID_INSTANCE_ERROR;	
   if (instance == NULL)
 	return NPERR_INVALID_INSTANCE_ERROR;
-
+  
   D(bug("NPN_GetURL instance=%p\n", instance));
   NPError ret = invoke_NPN_GetURL(instance, url, target);
   D(bug(" return: %d [%s]\n", ret, string_of_NPError(ret)));
@@ -655,6 +674,9 @@ invoke_NPN_GetURLNotify(NPP instance, co
 static NPError
 g_NPN_GetURLNotify(NPP instance, const char *url, const char *target, void *notifyData)
 {
+  if(!pid_check())
+	return NPERR_INVALID_INSTANCE_ERROR;
+	
   if (instance == NULL)
 	return NPERR_INVALID_INSTANCE_ERROR;
 
@@ -743,8 +765,11 @@ get_real_netscape_window(NPP instance)
 
 static NPError
 g_NPN_GetValue(NPP instance, NPNVariable variable, void *value)
-{
+{	
   D(bug("NPN_GetValue instance=%p, variable=%d [%08x]\n", instance, variable & 0xffff, variable));
+	
+  if(!pid_check())
+	return NPERR_INVALID_INSTANCE_ERROR;
 
   switch (variable) {
   case NPNVxDisplay:
@@ -837,6 +862,9 @@ g_NPN_InvalidateRect(NPP instance, NPRec
 {
   if (instance == NULL || invalidRect == NULL)
 	return;
+      
+  if(!pid_check())
+      return NPERR_INVALID_INSTANCE_ERROR;
 
   D(bug("NPN_InvalidateRect instance=%p\n", instance));
   invoke_NPN_InvalidateRect(instance, invalidRect);
@@ -848,6 +876,9 @@ static void
 g_NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
 {
   D(bug("NPN_InvalidateRegion instance=%p\n", instance));
+	
+  if(!pid_check())
+	return NPERR_INVALID_INSTANCE_ERROR;
 
   UNIMPLEMENTED();
 }
@@ -911,6 +942,8 @@ invoke_NPN_PostURL(NPP instance, const c
 static NPError
 g_NPN_PostURL(NPP instance, const char *url, const char *target, uint32 len, const char *buf, NPBool file)
 {
+  if(!pid_check())
+	return NPERR_INVALID_INSTANCE_ERROR;
   if (instance == NULL)
 	return NPERR_INVALID_INSTANCE_ERROR;
 
@@ -953,6 +986,9 @@ invoke_NPN_PostURLNotify(NPP instance, c
 static NPError
 g_NPN_PostURLNotify(NPP instance, const char *url, const char *target, uint32 len, const char *buf, NPBool file, void *notifyData)
 {
+  if(!pid_check())
+	return NPERR_INVALID_INSTANCE_ERROR;
+	
   if (instance == NULL)
 	return NPERR_INVALID_INSTANCE_ERROR;
 
@@ -967,6 +1003,9 @@ static void
 g_NPN_ReloadPlugins(NPBool reloadPages)
 {
   D(bug("NPN_ReloadPlugins reloadPages=%d\n", reloadPages));
+	
+  if(!pid_check())
+	return;
 
   UNIMPLEMENTED();
 }
@@ -976,6 +1015,9 @@ static JRIEnv *
 g_NPN_GetJavaEnv(void)
 {
   D(bug("NPN_GetJavaEnv\n"));
+	
+  if(!pid_check())
+	return NULL;
 
   return NULL;
 }
@@ -985,6 +1027,9 @@ static jref
 g_NPN_GetJavaPeer(NPP instance)
 {
   D(bug("NPN_GetJavaPeer instance=%p\n", instance));
+	
+  if(!pid_check())
+	return NULL;
 
   return NULL;
 }
@@ -1018,6 +1063,8 @@ invoke_NPN_RequestRead(NPStream *stream,
 static NPError
 g_NPN_RequestRead(NPStream *stream, NPByteRange *rangeList)
 {
+  if(!pid_check())
+	return NPERR_INVALID_INSTANCE_ERROR;
   if (stream == NULL || stream->ndata == NULL || rangeList == NULL)
 	return NPERR_INVALID_PARAM;
 
@@ -1066,10 +1113,13 @@ g_NPN_SetValue(NPP instance, NPPVariable
   if (instance == NULL)
 	return NPERR_INVALID_INSTANCE_ERROR;
 
+  if(!pid_check())
+      return NPERR_INVALID_INSTANCE_ERROR;
+
   PluginInstance *plugin = PLUGIN_INSTANCE(instance);
   if (plugin == NULL)
 	return NPERR_INVALID_INSTANCE_ERROR;
-
+      
   D(bug("NPN_SetValue instance=%p, variable=%d\n", instance, variable));
   NPError ret = invoke_NPN_SetValue(plugin, variable, value);
   D(bug(" return: %d [%s]\n", ret, string_of_NPError(ret)));
@@ -1102,6 +1152,9 @@ invoke_NPN_Status(NPP instance, const ch
 static void
 g_NPN_Status(NPP instance, const char *message)
 {
+  if(!pid_check())
+	return NPERR_INVALID_INSTANCE_ERROR;
+  
   D(bug("NPN_Status instance=%p\n", instance));
   invoke_NPN_Status(instance, message);
   D(bug(" done\n"));
@@ -1130,6 +1183,9 @@ invoke_NPN_UserAgent(void)
 static const char *
 g_NPN_UserAgent(NPP instance)
 {
+  if(!pid_check())
+	return NPERR_INVALID_INSTANCE_ERROR;
+  
   D(bug("NPN_UserAgent instance=%p\n", instance));
   if (g_user_agent == NULL)
 	g_user_agent = invoke_NPN_UserAgent();
@@ -1212,6 +1268,8 @@ invoke_NPN_NewStream(NPP instance, NPMIM
 static NPError
 g_NPN_NewStream(NPP instance, NPMIMEType type, const char *target, NPStream **stream)
 {
+  if(!pid_check())
+	return NPERR_INVALID_INSTANCE_ERROR;
   if (instance == NULL)
 	return NPERR_INVALID_INSTANCE_ERROR;
 
@@ -1257,6 +1315,9 @@ invoke_NPN_DestroyStream(NPP instance, N
 static NPError
 g_NPN_DestroyStream(NPP instance, NPStream *stream, NPError reason)
 {
+  if(!pid_check())
+	return NPERR_INVALID_INSTANCE_ERROR;
+  
   if (instance == NULL)
 	return NPERR_INVALID_INSTANCE_ERROR;
 
@@ -1314,6 +1375,9 @@ invoke_NPN_Write(NPP instance, NPStream 
 static int32
 g_NPN_Write(NPP instance, NPStream *stream, int32 len, void *buf)
 {
+  if(!pid_check())
+	return -1;
+  
   if (instance == NULL)
 	return -1;
 
@@ -1350,6 +1414,8 @@ invoke_NPN_PushPopupsEnabledState(NPP in
 static void
 g_NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
 {
+  if(!pid_check())
+	return;
   if (instance == NULL)
 	return;
 
@@ -1381,6 +1447,8 @@ invoke_NPN_PopPopupsEnabledState(NPP ins
 static void
 g_NPN_PopPopupsEnabledState(NPP instance)
 {
+  if(!pid_check())
+	return;
   if (instance == NULL)
 	return;
 
@@ -1480,6 +1548,9 @@ invoke_NPN_CreateObject(NPP instance)
 static NPObject *
 g_NPN_CreateObject(NPP instance, NPClass *class)
 {
+  if(!pid_check())
+	return NULL;
+  
   if (instance == NULL)
 	return NULL;
 
@@ -1520,6 +1591,9 @@ invoke_NPN_RetainObject(NPObject *npobj)
 static NPObject *
 g_NPN_RetainObject(NPObject *npobj)
 {
+  if(!pid_check())
+	return NULL;
+	
   if (npobj == NULL)
 	return NULL;
 
@@ -1558,6 +1632,9 @@ invoke_NPN_ReleaseObject(NPObject *npobj
 static void
 g_NPN_ReleaseObject(NPObject *npobj)
 {
+  if(!pid_check())
+	return;
+	
   if (npobj == NULL)
 	return;
 
@@ -1605,6 +1682,9 @@ static bool
 g_NPN_Invoke(NPP instance, NPObject *npobj, NPIdentifier methodName,
 			 const NPVariant *args, uint32_t argCount, NPVariant *result)
 {
+  if(!pid_check())
+	return false;
+	
   if (!instance || !npobj || !npobj->_class || !npobj->_class->invoke)
 	return false;
 
@@ -1652,6 +1732,9 @@ static bool
 g_NPN_InvokeDefault(NPP instance, NPObject *npobj,
 					const NPVariant *args, uint32_t argCount, NPVariant *result)
 {
+  if(!pid_check())
+	return false;
+	
   if (!instance || !npobj || !npobj->_class || !npobj->_class->invokeDefault)
 	return false;
 
@@ -1697,6 +1780,9 @@ invoke_NPN_Evaluate(NPP instance, NPObje
 static bool
 g_NPN_Evaluate(NPP instance, NPObject *npobj, NPString *script, NPVariant *result)
 {
+  if(!pid_check())
+	return false;
+	
   if (!instance || !npobj)
 	return false;
 
@@ -1746,6 +1832,9 @@ static bool
 g_NPN_GetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName,
 				  NPVariant *result)
 {
+  if(!pid_check())
+	return false;
+	
   if (!instance || !npobj || !npobj->_class || !npobj->_class->getProperty)
 	return false;
 
@@ -1792,6 +1881,9 @@ static bool
 g_NPN_SetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName,
 				  const NPVariant *value)
 {
+  if(!pid_check())
+	return false;
+	
   if (!instance || !npobj || !npobj->_class || !npobj->_class->setProperty)
 	return false;
 
@@ -1833,6 +1925,9 @@ invoke_NPN_RemoveProperty(NPP instance, 
 static bool
 g_NPN_RemoveProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
 {
+  if(!pid_check())
+	return false;
+	
   if (!instance || !npobj || !npobj->_class || !npobj->_class->removeProperty)
 	return false;
 
@@ -1874,6 +1969,9 @@ invoke_NPN_HasProperty(NPP instance, NPO
 static bool
 g_NPN_HasProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
 {
+  if(!pid_check())
+	return false;
+	
   if (!instance || !npobj || !npobj->_class || !npobj->_class->hasProperty)
 	return false;
 
@@ -1915,6 +2013,9 @@ invoke_NPN_HasMethod(NPP instance, NPObj
 static bool
 g_NPN_HasMethod(NPP instance, NPObject *npobj, NPIdentifier methodName)
 {
+  if(!pid_check())
+	return false;
+	
   if (!instance || !npobj || !npobj->_class || !npobj->_class->hasMethod)
 	return false;
 
@@ -1950,6 +2051,9 @@ invoke_NPN_SetException(NPObject *npobj,
 static void
 g_NPN_SetException(NPObject *npobj, const NPUTF8 *message)
 {
+  if(!pid_check())
+	return;
+	
   D(bug("NPN_SetException npobj=%p, message='%s'\n", npobj, message));
   invoke_NPN_SetException(npobj, message);
   D(bug(" done\n"));
@@ -2011,6 +2115,8 @@ invoke_NPN_GetStringIdentifier(const NPU
 static NPIdentifier
 g_NPN_GetStringIdentifier(const NPUTF8 *name)
 {
+  if(!pid_check())
+	return NULL;
   if (name == NULL)
 	return NULL;
 
@@ -2060,6 +2166,9 @@ invoke_NPN_GetStringIdentifiers(const NP
 static void
 g_NPN_GetStringIdentifiers(const NPUTF8 **names, uint32_t nameCount, NPIdentifier *identifiers)
 {
+  if(!pid_check())
+	return;
+  
   if (names == NULL)
 	return;
 
@@ -2101,6 +2210,9 @@ invoke_NPN_GetIntIdentifier(int32_t inti
 static NPIdentifier
 g_NPN_GetIntIdentifier(int32_t intid)
 {
+  if(!pid_check())
+	return 0;
+	
   D(bug("NPN_GetIntIdentifier intid=%d\n", intid));
   NPIdentifier ret = invoke_NPN_GetIntIdentifier(intid);
   D(bug(" return: %p\n", ret));
@@ -2137,6 +2249,9 @@ invoke_NPN_IdentifierIsString(NPIdentifi
 static bool
 g_NPN_IdentifierIsString(NPIdentifier identifier)
 {
+  if(!pid_check())
+	return false;
+	
   D(bug("NPN_IdentifierIsString identifier=%p\n", identifier));
   bool ret = invoke_NPN_IdentifierIsString(identifier);
   D(bug(" return: %d\n", ret));
@@ -2173,6 +2288,9 @@ invoke_NPN_UTF8FromIdentifier(NPIdentifi
 static NPUTF8 *
 g_NPN_UTF8FromIdentifier(NPIdentifier identifier)
 {
+  if(!pid_check())
+	return NULL;
+  
   D(bug("NPN_UTF8FromIdentifier identifier=%p\n", identifier));
   NPUTF8 *ret = invoke_NPN_UTF8FromIdentifier(identifier);
   D(bug(" return: '%s'\n", ret));
@@ -2210,6 +2328,9 @@ invoke_NPN_IntFromIdentifier(NPIdentifie
 static int32_t
 g_NPN_IntFromIdentifier(NPIdentifier identifier)
 {
+  if(!pid_check())
+	return 0;
+	
   D(bug("NPN_IntFromIdentifier identifier=%p\n", identifier));
   int32_t ret = invoke_NPN_IntFromIdentifier(identifier);
   D(bug(" return: %d\n", ret));
@@ -3259,6 +3380,9 @@ static int do_main(int argc, char **argv
   }
   D(bug("  Plugin connection: %s\n", connection_path));
 
+  pid_set();
+  D(bug("  Plugin viewer pid: %d\n", viewer_pid));
+  
   // Cleanup environment, the program may fork/exec a native shell
   // script and having 32-bit libraries in LD_PRELOAD is not right,
   // though not a fatal error