View Issue Details

IDProjectCategoryView StatusLast Update
0002019libextractorpluginspublic2012-09-25 17:18
ReporterLRNAssigned ToChristian Grothoff 
PrioritylowSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version0.6.3 
Target Version1.0.0Fixed in Version1.0.0 
Summary0002019: [patch] W32: Communicate mapping size to the children. Fix pipe inheritance.
DescriptionVirtualQuery() does not return the precise mapping size. Therefore it is necessary to convey the size via pipe along with mapping name.

Also, pipes should be created uninheritable.

Patch is attached.
TagsNo tags attached.

Activities

LRN

2011-12-21 12:28

developer  

patch3.diff (3,523 bytes)
Index: src/main/extractor.c
===================================================================
--- src/main/extractor.c	(revision 18734)
+++ src/main/extractor.c	(working copy)
@@ -1174,8 +1174,10 @@
 {
   char hfn[256];
   char tfn[256];
+  char sze[256];
   size_t hfn_len;
   size_t tfn_len;
+  size_t sze_len;
   char *fn;
   FILE *fin;
   void *ptr;
@@ -1256,6 +1258,15 @@
 	{
 	  fn = hfn;	
 	}
+      if (NULL == fgets (sze, sizeof(sze), fin))
+	break;
+      if ('s' != sze[0])
+	break;
+      sze_len = strlen (sze);
+      sze[--sze_len] = '\0'; /* kill newline */
+      size = strtol (&sze[1], NULL, 10);
+      if (size == LONG_MIN || size == LONG_MAX || size == 0)
+        break;
       do_break = 0;
 #ifndef WINDOWS
       if ( (-1 != (shmid = shm_open (fn, O_RDONLY, 0))) &&
@@ -1268,16 +1279,11 @@
       ptr = MapViewOfFile (map, FILE_MAP_READ, 0, 0, 0);
       if (ptr != NULL)
       {
-        size = VirtualQuery (ptr, &mi, sizeof (mi));
-        if (size == 0)
+        if (0 == VirtualQuery (ptr, &mi, sizeof (mi)) || mi.RegionSize < size)
         {
           UnmapViewOfFile (ptr);
           ptr = NULL;
         }
-        else
-        {
-          size = mi.RegionSize;
-        }
       }
       if (ptr != NULL)
 #endif
@@ -1495,12 +1501,12 @@
   HANDLE p10_os_inh = INVALID_HANDLE_VALUE, p21_os_inh = INVALID_HANDLE_VALUE;
 
   plugin->hProcess = NULL;
-  if (0 != _pipe (p1, 0, _O_BINARY))
+  if (0 != _pipe (p1, 0, _O_BINARY | _O_NOINHERIT))
     {
       plugin->flags = EXTRACTOR_OPTION_DISABLED;
       return;
     }
-  if (0 != _pipe (p2, 0, _O_BINARY))
+  if (0 != _pipe (p2, 0, _O_BINARY | _O_NOINHERIT))
     {
       close (p1[0]);
       close (p1[1]);
@@ -1587,6 +1593,7 @@
  * actual code of the plugin out-of-process.
  *
  * @param plugin which plugin to call
+ * @param size size of the file mapped by shmfn or tshmfn
  * @param shmfn file name of the shared memory segment
  * @param tshmfn file name of the shared memory segment for the end of the data
  * @param proc function to call on the meta data
@@ -1595,6 +1602,7 @@
  */
 static int
 extract_oop (struct EXTRACTOR_PluginList *plugin,
+             size_t size,
 	     const char *shmfn,
 	     const char *tshmfn,
 	     EXTRACTOR_MetaDataProcessor proc,
@@ -1638,6 +1646,20 @@
 	plugin->flags = EXTRACTOR_OPTION_DISABLED;
       return 0;
     }
+  if (0 >= fprintf (plugin->cpipe_in, 
+		    "s%lu\n",
+		    size))
+    {
+      stop_process (plugin);
+#ifndef WINDOWS
+      plugin->cpid = -1;
+#else
+      plugin->hProcess = INVALID_HANDLE_VALUE;
+#endif
+      if (plugin->flags != EXTRACTOR_OPTION_DEFAULT_POLICY)
+	plugin->flags = EXTRACTOR_OPTION_DISABLED;
+      return 0;
+    }
   fflush (plugin->cpipe_in);
   while (1)
     {
@@ -1898,7 +1920,7 @@
       switch (flags)
 	{
 	case EXTRACTOR_OPTION_DEFAULT_POLICY:
-	  if (0 != extract_oop (ppos, fn, 
+	  if (0 != extract_oop (ppos, (tptr != NULL) ? tsize : size, fn, 
 				(tptr != NULL) ? tfn : NULL,
 				proc, proc_cls))
 	    {
@@ -1912,7 +1934,7 @@
 #endif
 	    {
 	      start_process (ppos);
-	      if (0 != extract_oop (ppos, fn, 
+	      if (0 != extract_oop (ppos, (tptr != NULL) ? tsize : size, fn, 
 				    (tptr != NULL) ? tfn : NULL,
 				    proc, proc_cls))
 		{
@@ -1922,7 +1944,7 @@
 	    }
 	  break;
 	case EXTRACTOR_OPTION_OUT_OF_PROCESS_NO_RESTART:
-	  if (0 != extract_oop (ppos, fn,
+	  if (0 != extract_oop (ppos, (tptr != NULL) ? tsize : size, fn, 
 				(tptr != NULL) ? tfn : NULL,
 				proc, proc_cls))
 	    {
patch3.diff (3,523 bytes)

Christian Grothoff

2011-12-25 18:32

manager   ~0005203

Fixed as suggested in SVN 18813.

Issue History

Date Modified Username Field Change
2011-12-21 12:28 LRN New Issue
2011-12-21 12:28 LRN File Added: patch3.diff
2011-12-25 17:53 Christian Grothoff Assigned To => Christian Grothoff
2011-12-25 17:53 Christian Grothoff Status new => assigned
2011-12-25 18:32 Christian Grothoff Note Added: 0005203
2011-12-25 18:32 Christian Grothoff Status assigned => resolved
2011-12-25 18:32 Christian Grothoff Fixed in Version => current SVN
2011-12-25 18:32 Christian Grothoff Resolution open => fixed
2011-12-25 18:33 Christian Grothoff Product Version => 0.6.3
2011-12-25 18:33 Christian Grothoff Target Version => current SVN
2012-01-22 21:14 Christian Grothoff Fixed in Version current SVN => 1.0.0
2012-01-22 21:14 Christian Grothoff Target Version current SVN => 1.0.0
2012-09-25 17:18 Christian Grothoff Status resolved => closed